ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zquest.cpp
Date: 2025-05-29 08:39:38
Exec Total Coverage
Lines: 2271 14910 15.2%
Functions: 48 744 6.5%
Branches: 1400 11115 12.6%

Line Branch Exec Source
1 #include "allegro/gui.h"
2 #include "base/files.h"
3 #include "base/mapscr.h"
4 #include "dialog/edit_region.h"
5
6 #include <memory>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <cstring>
10 #include <sstream>
11 #include <ctype.h>
12 #include <assert.h>
13 #include <time.h>
14 #include <vector>
15 #include <filesystem>
16 #include <base/new_menu.h>
17
18 #include "dialog/info_lister.h"
19 #ifdef __APPLE__
20 // malloc.h is deprecated, but malloc also lives in stdlib
21 #include <stdlib.h>
22 #else
23 #include <malloc.h>
24 #endif
25
26 #include "zalleg/zalleg.h"
27 #include "base/qrs.h"
28 #include "base/dmap.h"
29 #include "base/msgstr.h"
30 #include "base/packfile.h"
31 #include "base/cpool.h"
32 #include "base/autocombo.h"
33 #include "base/render.h"
34 #include "base/version.h"
35 #include "zq/autocombo/autopattern_base.h"
36 #include "zq/autocombo/pattern_basic.h"
37 #include "zq/autocombo/pattern_flatmtn.h"
38 #include "zq/autocombo/pattern_fence.h"
39 #include "zq/autocombo/pattern_cakemtn.h"
40 #include "zq/autocombo/pattern_relational.h"
41 #include "zq/autocombo/pattern_dungeoncarve.h"
42 #include "zq/autocombo/pattern_dormtn.h"
43 #include "zq/autocombo/pattern_tiling.h"
44 #include "zq/autocombo/pattern_replace.h"
45 #include "zq/autocombo/pattern_denseforest.h"
46 #include "zq/autocombo/pattern_extend.h"
47 #include "zq/render_hotkeys.h"
48 #include "zq/render_minimap.h"
49 #include "zq/render_tooltip.h"
50 #include "base/misctypes.h"
51 #include "parser/Compiler.h"
52 #include "base/zc_alleg.h"
53 #include "particles.h"
54 #include "dialog/combopool.h"
55 #include "dialog/alert.h"
56 #include "dialog/alertfunc.h"
57 #include "zq/gui/edit_autocombo.h"
58
59 #include <al5_img.h>
60 #include <loadpng.h>
61 #include <fmt/format.h>
62
63 #include "dialog/cheat_codes.h"
64 #include "dialog/set_password.h"
65 #include "dialog/foodlg.h"
66 #include "dialog/quest_rules.h"
67 #include "dialog/script_rules.h"
68 #include "dialog/headerdlg.h"
69 #include "dialog/ffc_editor.h"
70 #include "dialog/screen_data.h"
71 #include "dialog/edit_dmap.h"
72 #include "dialog/compilezscript.h"
73 #include "dialog/screen_enemies.h"
74 #include "dialog/enemypattern.h"
75 #include "dialog/sfxdata.h"
76 #include "dialog/mapstyles.h"
77 #include "dialog/externs.h"
78
79 #include "base/gui.h"
80 #include "gui/jwin_a5.h"
81 #include "gui/jwin.h"
82 #include "zc_list_data.h"
83 #include "gui/editbox.h"
84 #include "zq/zq_misc.h"
85 #include "zq/zq_tiles.h" // tile and combo code
86
87 #include "zq/zquest.h"
88 #include "zq/ffasm.h"
89 #include "zq/render.h"
90
91 // the following are used by both zelda.cc and zquest.cc
92 #include "base/zdefs.h"
93 #include "base/qrs.h"
94 #include "tiles.h"
95 #include "base/colors.h"
96 #include "base/qst.h"
97 #include "base/zsys.h"
98 #include "base/zapp.h"
99 #include "base/process_management.h"
100 #include "play_midi.h"
101 #include "sound/zcmusic.h"
102
103 #include "midi.h"
104 #include "sprite.h"
105 #include "fontsdat.h"
106 #include "base/jwinfsel.h"
107 #include "zq/zq_class.h"
108 #include "subscr.h"
109 #include "zq/zq_subscr.h"
110 #include "zc/ffscript.h"
111 #include "gui/EditboxNew.h"
112 #include "sfx.h"
113 #include "zq/zq_custom.h" // custom items and guys
114 #include "zq/zq_strings.h"
115 #include "zq/questReport.h"
116 #include <fstream>
117 #include "drawing.h"
118 #include "zconsole/ConsoleLogger.h"
119 #include "colorname.h"
120 #include "zq/zq_hotkey.h"
121 #include "zq/package.h"
122 #include "zq/zq_files.h"
123 #include "music_playback.h"
124
125 //Windows mmemory tools
126 #ifdef _WIN32
127 #include <windows.h>
128 #include <stdio.h>
129 #include <psapi.h>
130 #pragma comment(lib, "psapi.lib") // Needed to avoid linker issues. -Z
131 #endif
132
133 #ifdef __EMSCRIPTEN__
134 #include <emscripten/emscripten.h>
135 #endif
136
137 #define MIDI_TRACK_BUFFER_SIZE 50
138 extern CConsoleLoggerEx parser_console;
139
140 using ZScript::disassembled_script_data;
141 void write_script(vector<shared_ptr<ZScript::Opcode>> const& zasm, string& dest,
142 bool commented, map<string,disassembled_script_data>* scr_meta_map);
143
144 namespace fs = std::filesystem;
145
146 #if defined(ALLEGRO_WINDOWS)
147 static const char *data_path_name = "win_data_path";
148 static const char *midi_path_name = "win_midi_path";
149 static const char *image_path_name = "win_image_path";
150 static const char *tmusic_path_name = "win_tmusic_path";
151 static const char *last_quest_name = "win_last_quest";
152 static const char *qtname_name = "win_qtname%d";
153 static const char *qtpath_name = "win_qtpath%d";
154 #elif defined(ALLEGRO_LINUX)
155 static const char *data_path_name = "linux_data_path";
156 static const char *midi_path_name = "linux_midi_path";
157 static const char *image_path_name = "linux_image_path";
158 static const char *tmusic_path_name = "linux_tmusic_path";
159 static const char *last_quest_name = "linux_last_quest";
160 static const char *qtname_name = "linux_qtname%d";
161 static const char *qtpath_name = "linux_qtpath%d";
162 #elif defined(__APPLE__)
163 static const char *data_path_name = "macosx_data_path";
164 static const char *midi_path_name = "macosx_midi_path";
165 static const char *image_path_name = "macosx_image_path";
166 static const char *tmusic_path_name = "macosx_tmusic_path";
167 static const char *last_quest_name = "macosx_last_quest";
168 static const char *qtname_name = "macosx_qtname%d";
169 static const char *qtpath_name = "macosx_qtpath%d";
170 #endif
171
172 #include "base/win32.h"
173
174 #include "zq/zq_init.h"
175 #include "zq/zq_doors.h"
176 #include "zq/zq_cset.h"
177 #include "zinfo.h"
178
179 #ifdef _MSC_VER
180 #include <crtdbg.h>
181
182 #endif
183
184 // MSVC fix
185 #if _MSC_VER >= 1900
186 FILE _iob[] = { *stdin, *stdout, *stderr };
187 extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
188 #endif
189
190 extern byte monochrome_console;
191
192 #include "zconsole/ConsoleLogger.h"
193
194 extern CConsoleLoggerEx zscript_coloured_console;
195
196 uint8_t console_is_open = 0;
197 bool is_zq_replay_test = false;
198
199 #include "base/util.h"
200
201 #ifdef __EMSCRIPTEN__
202 #include "base/emscripten_utils.h"
203 #endif
204
205 using namespace util;
206
207 using std::vector;
208 using std::map;
209 using std::stringstream;
210
211 12 FFScript FFCore;
212
213 void load_size_poses();
214 void do_previewtext();
215 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
216 map<string, disassembled_script_data> &scripts, int assign_mode);
217
218 int32_t startdmapxy[6] = {-1000, -1000, -1000, -1000, -1000, -1000};
219 bool cancelgetnum=false;
220
221 int32_t tooltip_timer=0, tooltip_maxtimer=30, tooltip_current_ffc=0;
222 int32_t combobrushoverride=-1;
223 ComboPosition mouse_combo_pos;
224
225 int32_t original_playing_field_offset=0;
226 12 int32_t playing_field_offset=original_playing_field_offset;
227 int32_t passive_subscreen_height=56;
228
229 bool disable_saving=false, OverwriteProtection;
230 bool halt=false;
231 bool show_sprites=true;
232 bool show_hitboxes = false;
233 bool zq_ignore_item_ownership = true;
234
235 // Used to find FFC script names
236 vector<string> asffcscripts;
237 vector<string> asglobalscripts;
238 vector<string> asitemscripts;
239 vector<string> asnpcscripts;
240 vector<string> aseweaponscripts;
241 vector<string> aslweaponscripts;
242 vector<string> asplayerscripts;
243 vector<string> asdmapscripts;
244 vector<string> asscreenscripts;
245 vector<string> asitemspritescripts;
246 vector<string> ascomboscripts;
247 vector<string> asgenericscripts;
248 vector<string> assubscreenscripts;
249
250 vector<string> ZQincludePaths;
251
252 int32_t CSET_SIZE = 16;
253 int32_t CSET_SHFT = 4;
254 //editbox_data temp_eb_data;
255 /*
256 #define CSET(x) ((x)<<CSET_SHFT)
257 #define csBOSS 14
258 */
259
260 /*
261 enum { m_block, m_coords, m_flags, m_guy, m_warp, m_misc, m_layers,
262 m_menucount };
263 */
264 void update_combo_cycling();
265 void update_freeform_combos();
266
267 /*
268 #define MAXMICE 14
269 #define MAXARROWS 8
270 #define SHADOW_DEPTH 2
271 */
272 int32_t coord_timer=0, coord_frame=0;
273 int32_t blackout_color, zq_screen_w, zq_screen_h;
274 int32_t draw_mode=0;
275
276 12 size_and_pos minimap;
277 12 size_and_pos real_minimap;
278
279 12 size_and_pos minimap_zoomed;
280 12 size_and_pos real_minimap_zoomed;
281
282 12 size_and_pos map_page_bar[9];
283 int32_t mappage_count = 9;
284
285 12 size_and_pos combolist[MAX_COMBO_COLS];
286 12 size_and_pos combolistscrollers[MAX_COMBO_COLS];
287 int32_t num_combo_cols = MAX_COMBO_COLS;
288
289 static bool zoom_in_btn_disabled;
290 static bool zoom_out_btn_disabled;
291 12 size_and_pos zoominbtn;
292 12 size_and_pos zoomoutbtn;
293 12 size_and_pos compactbtn;
294 12 size_and_pos mainbar;
295
296 12 size_and_pos screrrorpos;
297
298 12 size_and_pos comboaliaslist[MAX_COMBO_COLS];
299 12 size_and_pos comboalias_preview;
300 12 size_and_pos combopool_preview;
301 12 size_and_pos combopool_prevbtn;
302
303 12 size_and_pos combo_merge_btn;
304
305 12 size_and_pos combo_preview;
306 12 size_and_pos combo_preview2;
307 12 size_and_pos combo_preview_text1;
308 12 size_and_pos combo_preview_text2;
309 12 size_and_pos combolist_window;
310 12 size_and_pos drawmode_btn;
311 12 size_and_pos main_panel;
312 12 size_and_pos squares_panel;
313 12 size_and_pos preview_panel;
314 12 size_and_pos layer_panel;
315 12 size_and_pos preview_text;
316
317 12 size_and_pos favorites_window;
318 12 size_and_pos favorites_list;
319 12 size_and_pos favorites_x;
320 12 size_and_pos favorites_infobtn;
321 12 size_and_pos favorites_zoombtn;
322 12 size_and_pos favorites_pgleft;
323 12 size_and_pos favorites_pgright;
324
325 12 size_and_pos commands_window;
326 12 size_and_pos commands_list;
327 12 size_and_pos commands_x;
328 12 size_and_pos commands_infobtn;
329 12 size_and_pos commands_zoombtn;
330 12 size_and_pos commands_txt;
331
332 12 size_and_pos squarepanel_swap_btn;
333 12 size_and_pos squarepanel_up_btn;
334 12 size_and_pos squarepanel_down_btn;
335 12 size_and_pos itemsqr_pos;
336 12 size_and_pos flagsqr_pos;
337 12 size_and_pos stairsqr_pos;
338 12 size_and_pos warparrival_pos;
339 12 size_and_pos warpret_pos[4];
340 12 size_and_pos enemy_prev_pos;
341
342 12 size_and_pos txtoffs_single;
343 12 size_and_pos txtoffs_double_1;
344 12 size_and_pos txtoffs_double_2;
345 int32_t panel_align = 1;
346
347 int32_t command_buttonwidth = 88;
348 int32_t command_buttonheight = 19;
349
350 int32_t layerpanel_buttonwidth = 58;
351 int32_t layerpanel_buttonheight = 16;
352
353 int32_t layerpanel_checkbox_hei = 13;
354 int32_t layerpanel_checkbox_wid = 13;
355
356 int32_t favorite_combos[MAXFAVORITECOMBOS];
357 byte favorite_combo_modes[MAXFAVORITECOMBOS];
358 bool ShowFavoriteComboModes;
359 byte FavoriteComboPage;
360
361 char comboprev_buf[512] = {0};
362 char comboprev_buf2[512] = {0};
363 FONT* txfont;
364
365 const char *roomtype_string[MAXROOMTYPES] =
366 {
367 "(None)","Special Item","Pay for Info","Secret Money","Gamble",
368 "Door Repair","Red Potion or Heart Container","Feed the Goriya","Triforce Check",
369 "Potion Shop","Shop","More Bombs","Leave Money or Life","10 Rupees",
370 "3-Stair Warp","Ganon","Zelda", "-<item pond>", "1/2 Magic Upgrade", "Learn Slash", "More Arrows","Take One Item"
371 };
372
373 const char *catchall_string[MAXROOMTYPES] =
374 {
375 "Generic Catchall","Special Item","Info Type","Amount","Generic Catchall","Repair Fee","Generic Catchall","Generic Catchall","Generic Catchall","Shop Type",
376 "Shop Type","Price","Price","Generic Catchall","Warp Ring","Generic Catchall","Generic Catchall", "Generic Catchall", "Generic Catchall",
377 "Generic Catchall", "Price","Shop Type","Bottle Shop Type"
378 };
379
380 #define MAXPOOLCOMBOS MAXFAVORITECOMBOS
381
382 struct cmbdat_pair
383 {
384 int32_t data;
385 byte cset;
386 15120 cmbdat_pair() { clear(); }
387 25200 void clear()
388 {
389 25200 data = -1;
390 25200 cset = 0;
391 25200 }
392 bool valid() const
393 {
394 return data > -1;
395 }
396 };
397 bool pool_dirty=true;
398 12 cmbdat_pair pool_combos[MAXPOOLCOMBOS];
399 static std::vector<byte> pool;
400
401 bool pool_valid()
402 {
403 if(pool_dirty)
404 {
405 pool.clear();
406 for(auto q = 0; q < MAXPOOLCOMBOS; ++q)
407 {
408 if(pool_combos[q].valid())
409 pool.push_back(q);
410 }
411 pool_dirty = false;
412 }
413 return pool.size() > 0;
414 }
415 cmbdat_pair const& get_pool_combo()
416 {
417 if(!pool_valid()) return pool_combos[0];
418 auto ind = zc_rand(pool.size()-1);
419 return pool_combos[pool.at(ind)];
420 }
421
422 int32_t mouse_scroll_h;
423
424 // 'mapscreen' refers to the area of the editor where the screen is drawn.
425 int32_t mapscreen_x, mapscreen_y, showedges, showallpanels;
426 // The scale of the entire mapscreen area. This varies based on compact/extended mode.
427 static int mapscreen_screenunit_scale;
428 // The scale of an individual screen being drawn. This is `mapscreen_screenunit_scale / Map.getViewSize()`.
429 static double mapscreen_single_scale;
430 // 4 is roughly the largest value where things render okay. Beyond that, our low bitmap resolution results in tons
431 // of downsampling. Let users go to 16 anyway.
432 static int mapscreen_num_screens_to_draw_max = 16;
433 // The valid layers for the current screen(s).
434 static bool mapscreen_valid_layers[6];
435
436 struct VisibleScreen
437 {
438 int dx, dy;
439 int xoff, yoff;
440 mapscr* scr;
441 int screen;
442 };
443 static std::vector<VisibleScreen> visible_screens;
444 static VisibleScreen* active_visible_screen = nullptr;
445
446 static void set_active_visible_screen(mapscr* scr)
447 {
448 active_visible_screen = nullptr;
449 for (auto& visible_screen : visible_screens)
450 {
451 if (visible_screen.scr == scr)
452 {
453 active_visible_screen = &visible_screen;
454 break;
455 }
456 }
457 }
458
459 static ComboPosition get_mapscreen_mouse_combo_pos()
460 {
461 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
462 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
463 int cx = (gui_mouse_x()-startxint)/(16*mapscreen_single_scale);
464 int cy = (gui_mouse_y()-startyint)/(16*mapscreen_single_scale);
465 return ComboPosition{cx, cy};
466 }
467
468 static void refresh_visible_screens()
469 {
470 int num_screens = Map.getViewSize();
471 int screen_width = mapscreenbmp->w * mapscreen_single_scale;
472 int screen_height = mapscreenbmp->h * mapscreen_single_scale;
473
474 visible_screens.clear();
475 for (int dx = 0; dx < num_screens; dx++)
476 {
477 for (int dy = 0; dy < num_screens; dy++)
478 {
479 int mx = Map.getViewScr()%16 + dx;
480 int my = Map.getViewScr()/16 + dy;
481 if (mx < 0 || mx >= 16 || my < 0 || my >= 9)
482 continue;
483
484 int screen = Map.getViewScr() + dx + dy * 16;
485 if (screen >= MAPSCRS)
486 continue;
487
488 mapscr* scr = Map.Scr(screen);
489 int offx = dx * screen_width;
490 int offy = dy * screen_height;
491 visible_screens.emplace_back(VisibleScreen{dx, dy, offx, offy, scr, screen});
492 }
493 }
494
495 for (int i = 0; i < 6; i++)
496 {
497 mapscreen_valid_layers[i] = false;
498 for (auto& vis_screen : visible_screens)
499 {
500 mapscreen_valid_layers[i] |= vis_screen.scr->layermap[i] > 0;
501 }
502 }
503 }
504
505 int32_t readsize, writesize;
506 bool fake_pack_writing=false;
507
508 int32_t showxypos_x;
509 int32_t showxypos_y;
510 int32_t showxypos_w;
511 int32_t showxypos_h;
512 int32_t showxypos_color;
513 int32_t showxypos_ffc=-1000;
514 bool showxypos_icon=false;
515
516 int32_t showxypos_cursor_x;
517 int32_t showxypos_cursor_y;
518 bool showxypos_cursor_icon=false;
519 int32_t showxypos_cursor_color;
520 bool showxypos_dummy = false;
521
522 bool canfill=true; //to prevent double-filling (which stops undos)
523 int32_t lens_hint_item[MAXITEMS][2]; //aclk, aframe
524 int32_t lens_hint_weapon[MAXWPNS][5]; //aclk, aframe, dir, x, y
525 //int32_t mode, switch_mode, orig_mode;
526 int32_t tempmode=GFX_AUTODETECT;
527 RGB_MAP zq_rgb_table;
528 COLOR_MAP trans_table, trans_table2;
529 MIDI *song=NULL;
530 BITMAP *menu1, *menu3, *mapscreenbmp, *tmp_scr, *screen2, *mouse_bmp[MOUSE_BMP_MAX][4], *mouse_bmp_1x[MOUSE_BMP_MAX][4], *icon_bmp[ICON_BMP_MAX][4], *flag_bmp[16][4], *select_bmp[2], *dmapbmp_small, *dmapbmp_large;
531 BITMAP *arrow_bmp[MAXARROWS],*brushbmp, *brushscreen; //*brushshadowbmp;
532 byte *colordata=NULL, *trashbuf=NULL;
533 itemdata *itemsbuf;
534 wpndata *wpnsbuf;
535 comboclass *combo_class_buf;
536 guydata *guysbuf;
537 item_drop_object item_drop_sets[MAXITEMDROPSETS];
538 12 newcombo curr_combo;
539 PALETTE RAMpal;
540 midi_info Midi_Info;
541 bool zq_showpal=false;
542 bool is_compact = false;
543
544 int pixeldb = 1;
545 int infobg = 1;
546 bool large_merged_combopane = false;
547 bool compact_merged_combopane = true;
548 bool large_zoomed_fav = false;
549 bool compact_zoomed_fav = true;
550 bool large_zoomed_cmd = false;
551 bool compact_zoomed_cmd = true;
552
553 bool compact_square_panels = false;
554 int compact_active_panel = 0;
555
556 int combo_col_scale = 1;
557
558 std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
559 script_data *ffscripts[NUMSCRIPTFFC];
560 script_data *itemscripts[NUMSCRIPTITEM];
561 script_data *guyscripts[NUMSCRIPTGUYS];
562 script_data *lwpnscripts[NUMSCRIPTWEAPONS];
563 script_data *ewpnscripts[NUMSCRIPTWEAPONS];
564 script_data *globalscripts[NUMSCRIPTGLOBAL];
565 script_data *genericscripts[NUMSCRIPTSGENERIC];
566 script_data *playerscripts[NUMSCRIPTHERO];
567 script_data *screenscripts[NUMSCRIPTSCREEN];
568 script_data *dmapscripts[NUMSCRIPTSDMAP];
569 script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
570 script_data *comboscripts[NUMSCRIPTSCOMBODATA];
571 script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
572
573 extern string zScript;
574 char zScriptBytes[512];
575 char zLastVer[512] = { 0 };
576 SAMPLE customsfxdata[WAV_COUNT];
577 uint8_t customsfxflag[WAV_COUNT>>3];
578 int32_t sfxdat=1;
579
580 int32_t onImport_ComboAlias();
581 int32_t onExport_ComboAlias();
582
583 void set_console_state();
584
585 void clearConsole()
586 {
587 if(!console_is_open) return;
588 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
589 zscript_coloured_console.gotoxy(0,0);
590 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
591 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
592 }
593
594 void initConsole()
595 {
596 if(console_is_open) return;
597 console_is_open = 1;
598 set_console_state();
599 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
600 clearConsole();
601 }
602
603 11 void killConsole()
604 {
605
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(!console_is_open) return;
606 console_is_open = 0;
607 set_console_state();
608 zscript_coloured_console.kill();
609 11 }
610
611 int toggleConsole()
612 {
613 console_is_open ? killConsole() : initConsole();
614 zc_set_config("zquest","open_debug_console",console_is_open?1:0);
615 return D_O_K;
616 }
617
618 int showHotkeys()
619 {
620 hotkeys_toggle_display(!hotkeys_is_active());
621 return D_O_K;
622 }
623
624 typedef int32_t (*intF)();
625 typedef struct command_pair
626 {
627 char name[80];
628 int32_t flags;
629 intF command;
630 } command_pair;
631
632 extern map_and_screen map_page[MAX_MAPPAGE_BTNS];
633
634 int32_t do_OpenQuest()
635 {
636 return onOpen();
637 }
638
639 int32_t do_NewQuest()
640 {
641 //clear the panel recent screen buttons to prevent crashes from invalid maps
642 for ( int32_t q = 0; q < 9; q++ )
643 {
644 map_page[q].map = 0;
645 map_page[q].screen = 0;
646 }
647 Map.setCurrMap(0);
648 Map.setCurrScr(0);
649 return onNew();
650 }
651
652 extern int CheckerCol1, CheckerCol2;
653 int32_t alignment_arrow_timer=0;
654 int32_t Flip=0,Combo=0,CSet=2,current_combolist=0,current_comboalist=0,current_cpoollist=0,current_cautolist=0,current_mappage=0;
655 int32_t Flags=0,Flag=0,menutype=(m_block);
656 int MouseScroll = 0, SavePaths = 0, CycleOn = 0, ShowGrid = 0, ShowScreenGrid = 0, ShowRegionGrid = 0, GridColor = 15, ShowCurScreenOutline = 1,
657 CmbCursorCol = 15, TilePgCursorCol = 15, CmbPgCursorCol = 15, TTipHLCol = 13,
658 TileProtection = 0, ComboProtection = 0, NoScreenPreview = 0, MMapCursorStyle = 0,
659 LayerDitherBG = -1, LayerDitherSz = 2, RulesetDialog = 0,
660 EnableTooltips = 0, TooltipsHighlight = 0, ShowFFScripts = 0, ShowSquares = 0,
661 ShowFFCs = 0, ShowInfo = 0, skipLayerWarning = 0,
662 DisableLPalShortcuts = 1, DisableCompileConsole = 0, numericalFlags = 0,
663 ActiveLayerHighlight = 0, DragCenterOfSquares = 0;
664 uint8_t InvalidBG = 0;
665 bool NoHighlightLayer0 = false;
666 int32_t FlashWarpSquare = -1, FlashWarpClk = 0; // flash the destination warp return when ShowSquares is active
667 uint8_t ViewLayer3BG = 0, ViewLayer2BG = 0;
668 int32_t window_width, window_height;
669 bool ShowFPS = false, SaveDragResize = false, DragAspect = false, SaveWinPos=false;
670 bool allowHideMouse = false;
671 double aspect_ratio = LARGE_H / double(LARGE_W);
672 int window_min_width = 0, window_min_height = 0;
673 int32_t ComboBrush = 0; //show the brush instead of the normal mouse
674 int32_t ComboBrushPause = 0; //temporarily disable the combo brush
675 int32_t FloatBrush = 0; //makes the combo brush float a few pixels up and left
676 int AutoBrush = 0; //Drag to size the brush on the combo panes
677 bool AutoBrushRevert = false; //Revert after placing
678 int LinkedScroll = 0;
679 //complete with shadow
680 int32_t OpenLastQuest = 0; //makes the program reopen the quest that was
681 //open at the time you quit
682 int32_t ShowMisalignments = 0; //makes the program display arrows over combos that are
683 //not aligned with the next screen.
684 int32_t AnimationOn = 0; //animate the combos in zquest?
685 int32_t AutoBackupRetention = 0; //use auto-backup feature? if so, how many backups (1-10) to keep
686 int32_t AutoSaveInterval = 0; //how often a timed autosave is made (not overwriting the current file)
687 int32_t UncompressedAutoSaves = 0; //should timed saves be uncompressed/encrypted?
688 int32_t KeyboardRepeatDelay = 0; //the time in milliseconds after holding down a key that the key starts to repeat
689 int32_t KeyboardRepeatRate = 0; //the time in milliseconds between each repetition of a repeated key
690
691 time_t auto_save_time_start, auto_save_time_current;
692 double auto_save_time_diff = 0;
693 int32_t AutoSaveRetention = 0; //how many autosaves of a quest to keep
694 int32_t ImportMapBias = 0; //tells what has precedence on map importing
695 int32_t BrushWidth=1, BrushHeight=1;
696 bool saved=true;
697 bool __debug=false;
698 int32_t LayerMaskInt[7]={0};
699 int32_t CurrentLayer=0;
700 int32_t DuplicateAction[4]={0};
701 int32_t OnlyCheckNewTilesForDuplicates = 0;
702 int32_t try_recovering_missing_scripts = 0;
703
704 uint8_t PreFillTileEditorPage = 0, PreFillComboEditorPage = 0;
705 int32_t DMapEditorLastMaptileUsed = 0;
706
707 /*
708 , HorizontalDuplicateAction;
709 int32_t VerticalDuplicateAction, BothDuplicateAction;
710 */
711 word msg_count = 0;
712 int32_t LeechUpdate = 0;
713 int32_t LeechUpdateTiles = 0;
714 int32_t SnapshotFormat = 0;
715 byte SnapshotScale = 0;
716
717 byte Color = 0;
718 extern int32_t jwin_pal[jcMAX];
719 int32_t gui_colorset=99;
720
721 static int32_t combo_apos=0; //currently selected combo alias
722 int32_t alias_origin=0;
723 int32_t alias_cset_mod=0;
724
725 static int32_t combo_pool_pos=0; //currently selected combo pool
726 bool weighted_cpool = true;
727 bool cpool_prev_visible = false;
728
729 static int32_t combo_auto_pos=0; //currently selected autocombo
730 byte cauto_height = 1;
731
732 bool trip=false;
733
734 int32_t fill_type=1;
735
736 bool first_save=false;
737 char *filepath,*midipath,*datapath,*imagepath,*tmusicpath,*last_timed_save;
738 string helpstr, zstringshelpstr;
739
740 ZCMUSIC *zcmusic = NULL;
741 ZCMIXER *zcmixer = NULL;
742 int32_t midi_volume = 255;
743 extern int32_t prv_mode;
744 int32_t prv_warp = 0;
745 int32_t prv_twon = 0;
746 int32_t ff_combo = 0;
747
748 int32_t Frameskip = 0, RequestedFPS = 60, zqUseWin32Proc = 1;
749 int32_t zqColorDepth = 8;
750 int32_t joystick_index=0;
751
752 11 void set_last_timed_save(char const* buf)
753 {
754
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
11 if(buf && buf[0])
755 {
756 if(buf != last_timed_save)
757 strcpy(last_timed_save, buf);
758 }
759 else
760 {
761 11 last_timed_save[0] = 0;
762 11 buf = nullptr;
763 }
764 11 zc_set_config("zquest","last_timed_save",buf);
765 11 }
766
767 void loadlvlpal(int32_t level);
768 bool get_debug()
769 {
770 return __debug;
771 //return true;
772 }
773
774 void set_debug(bool d)
775 {
776 __debug=d;
777 return;
778 }
779
780 bool handle_quit()
781 {
782 if(onExit()==D_CLOSE)
783 return (exiting_program = true);
784 return false;
785 }
786 bool handle_close_btn_quit()
787 {
788 if(close_button_quit)
789 {
790 close_button_quit=false;
791 return handle_quit();
792 }
793 return false;
794 }
795 // **** Timers ****
796
797 volatile int32_t lastfps=0;
798 volatile int32_t framecnt=0;
799 size_t cpoolbrush_index = 0;
800
801 // quest data
802 12 zquestheader header;
803 byte midi_flags[MIDIFLAGS_SIZE];
804 byte music_flags[MUSICFLAGS_SIZE];
805 byte *quest_file;
806 int32_t msg_strings_size;
807 zctune *customtunes;
808 //emusic *enhancedMusic;
809 ZCHEATS zcheats;
810 byte use_cheats;
811 byte use_tiles;
812 // Note: may not be null-terminated (must refactor writecolordata to fix).
813 char palnames[MAXLEVELS][17];
814 char zquestdat_sig[52];
815 char qstdat_str[2048];
816
817 int32_t gme_track=0;
818
819 int32_t dlevel; // just here until gamedata is properly done
820
821 12 bool bad_version(int32_t ver)
822 {
823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(ver < 0x170)
824 return true;
825
826 12 return false;
827 12 }
828
829 // These are for drawing eyeballs correctly in combo_tile.
830 zfix HeroModifiedX()
831 {
832 return gui_mouse_x() - 7;
833 }
834 zfix HeroModifiedY()
835 {
836 return gui_mouse_y() - 7;
837 }
838
839
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_250_menu
840 48 {
841
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
842
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onImport_Combos },
843
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onImport_ComboAlias },
844 };
845
846
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_graphics
847 180 {
848
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onImport_Pals },
849
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
850
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onImport_Tiles },
851
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onImport_Tilepack },
852
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "T&ile Pack to...", onImport_Tilepack_To },
853
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
854
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set (Range)", onImport_Combos },
855
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack (Full, 1:1)", onImport_Combopack },
856
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack to... (Dest)", onImport_Combopack_To },
857
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
858
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onImport_Comboaliaspack },
859
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo A&lias Pack to...", onImport_Comboaliaspack_To },
860
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
861
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onImport_Doorset },
862 };
863
864
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu import_menu
865 120 {
866
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onImport_Guys },
867
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onImport_Map },
868
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onImport_DMaps },
869
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onImport_StringsTSV },
870
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onImport_Msgs },
871
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
872
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &import_graphics },
873
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
874
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &import_250_menu },
875 };
876
877
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_250_menu
878 60 {
879
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
880
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Table", onExport_Combos },
881
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onExport_ComboAlias },
882
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics Pack", onExport_ZGP },
883 };
884
885
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zq_help_menu
886 36 {
887
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Editor Help", onHelp },
888
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings Help", onZstringshelp },
889 };
890
891
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_graphics
892 144 {
893
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onExport_Pals },
894
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
895
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Tileset (&Full)", onExport_Tiles },
896
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Pack", onExport_Tilepack },
897
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
898
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Set", onExport_Combos },
899
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo Pack", onExport_Combopack },
900
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
901
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Alias Pack", onExport_Comboaliaspack },
902
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
903
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doorsets", onExport_Doorset },
904 };
905
906
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu export_menu
907 132 {
908 #ifdef _WIN32
909 { "&Package", onExport_Package },
910 #endif
911
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onExport_Guys },
912
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map", onExport_Map },
913
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onExport_DMaps },
914
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
915
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings (.tsv)", onExport_StringsTSV },
916
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "String Table (deprecated)", onExport_Msgs },
917
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
918
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics", &export_graphics },
919
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
920
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2.50 (Broken)", &export_250_menu },
921 };
922
923
924
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu recent_menu
925 132 {
926
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
927
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
928
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
929
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
930
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
931
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
932
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
933
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
934
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
935
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
936 };
937 static char rec_menu_fullpaths[10][512];
938 static char rec_menu_strs[10][64];
939
940 int32_t customOpen(char const* path);
941 void do_recent_quest(uint32_t ind)
942 {
943 if(ind > 9) return;
944 strcpy(temppath, rec_menu_fullpaths[ind]);
945 customOpen(temppath);
946 }
947 int32_t do_RecentQuest_0() { do_recent_quest(0); return D_O_K; }
948 int32_t do_RecentQuest_1() { do_recent_quest(1); return D_O_K; }
949 int32_t do_RecentQuest_2() { do_recent_quest(2); return D_O_K; }
950 int32_t do_RecentQuest_3() { do_recent_quest(3); return D_O_K; }
951 int32_t do_RecentQuest_4() { do_recent_quest(4); return D_O_K; }
952 int32_t do_RecentQuest_5() { do_recent_quest(5); return D_O_K; }
953 int32_t do_RecentQuest_6() { do_recent_quest(6); return D_O_K; }
954 int32_t do_RecentQuest_7() { do_recent_quest(7); return D_O_K; }
955 int32_t do_RecentQuest_8() { do_recent_quest(8); return D_O_K; }
956 int32_t do_RecentQuest_9() { do_recent_quest(9); return D_O_K; }
957
958 2 void refresh_recent_menu()
959 {
960 2 int32_t (*procs[10])(void) = {
961 do_RecentQuest_0, do_RecentQuest_1, do_RecentQuest_2, do_RecentQuest_3,
962 do_RecentQuest_4, do_RecentQuest_5, do_RecentQuest_6,
963 do_RecentQuest_7, do_RecentQuest_8, do_RecentQuest_9
964 };
965
5/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 static MenuItem nilitem("---",nullptr,nullopt,true);
966
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 for(auto q = 0; q < 10; ++q)
967 {
968 20 MenuItem& mit = *recent_menu.at(q);
969 20 bool valid = rec_menu_fullpaths[q][0] != '-';
970
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(valid)
971 mit = MenuItem(rec_menu_strs[q],procs[q]);
972 20 else mit = nilitem;
973 20 }
974 2 }
975
976 1 void load_recent_quests()
977 {
978 1 char configname[64] = "rec_qst_";
979 1 char* ptr = &configname[strlen(configname)];
980 1 char buf[512] = {0};
981
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for(auto q = 0; q < 10; ++q)
982 {
983 10 sprintf(ptr, "%d", q); //increment the configname value
984 10 char const* qst_str = zc_get_config("recent",configname,nullptr);
985
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(qst_str[0])
986 {
987 strncpy(rec_menu_fullpaths[q], qst_str, 511);
988 relativize_path(buf, rec_menu_fullpaths[q]);
989 if(strlen(buf) > 62)
990 {
991 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
992 }
993 strncpy(rec_menu_strs[q], buf, 63);
994 }
995 else
996 {
997 10 strcpy(rec_menu_fullpaths[q], "---");
998 10 strcpy(rec_menu_strs[q], "---");
999 }
1000 10 rec_menu_fullpaths[q][511] = 0;
1001 10 rec_menu_strs[q][63] = 0;
1002 10 }
1003 1 refresh_recent_menu();
1004 1 }
1005
1006 void write_recent_quests()
1007 {
1008 char configname[64] = "rec_qst_";
1009 char* ptr = &configname[strlen(configname)];
1010 for(auto q = 0; q < 10; ++q)
1011 {
1012 sprintf(ptr, "%d", q); //increment the configname value
1013 zc_set_config("recent",configname,(rec_menu_fullpaths[q][0]!='-') ? rec_menu_fullpaths[q] : nullptr);
1014 }
1015 }
1016
1017 void update_recent_quest(char const* path)
1018 {
1019 int32_t ind = -1;
1020 for(auto q = 0; q < 10; ++q)
1021 {
1022 if(!strcmp(path, rec_menu_fullpaths[q]))
1023 {
1024 ind = q;
1025 break;
1026 }
1027 }
1028 if(ind > -1)
1029 {
1030 for(auto q = ind; q > 0; --q)
1031 {
1032 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1033 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1034 }
1035 }
1036 else
1037 {
1038 int32_t free_ind = 9; //if none found, override the last index
1039 for(auto q = 0; q < 9; ++q)
1040 {
1041 if(rec_menu_fullpaths[q][0] == '-')
1042 {
1043 free_ind = q;
1044 break;
1045 }
1046 }
1047
1048 for(auto q = free_ind; q > 0; --q)
1049 {
1050 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1051 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1052 }
1053 }
1054 char buf[512] = {0};
1055 strcpy(rec_menu_fullpaths[0], path);
1056 relativize_path(buf, rec_menu_fullpaths[0]);
1057 if(strlen(buf) > 62)
1058 {
1059 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
1060 }
1061 strncpy(rec_menu_strs[0], buf, 63);
1062 refresh_recent_menu();
1063 zc_set_config("zquest",last_quest_name,path);
1064 write_recent_quests();
1065 }
1066
1067 void reload_zq_gui()
1068 {
1069 init_custom_fonts();
1070 load_size_poses();
1071 refresh_visible_screens();
1072 update_combobrush();
1073 refresh(rCLEAR|rALL);
1074 }
1075 void change_mapscr_zoom(int delta)
1076 {
1077 int num_screens = Map.getViewSize();
1078 num_screens = std::clamp(num_screens + delta, 1, mapscreen_num_screens_to_draw_max);
1079 Map.setViewSize(num_screens);
1080 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
1081 zc_set_config(qst_cfg_header.c_str(), "zoom_num_screens", Map.getViewSize());
1082 reload_zq_gui();
1083 }
1084 void toggle_is_compact()
1085 {
1086 is_compact = !is_compact;
1087 zc_set_config("ZQ_GUI","compact_mode",is_compact?1:0);
1088 reload_zq_gui();
1089 }
1090 void toggle_merged_mode()
1091 {
1092 if(is_compact)
1093 {
1094 compact_merged_combopane = !compact_merged_combopane;
1095 zc_set_config("ZQ_GUI","merge_cpane_compact",compact_merged_combopane?1:0);
1096 }
1097 else
1098 {
1099 large_merged_combopane = !large_merged_combopane;
1100 zc_set_config("ZQ_GUI","merge_cpane_large",large_merged_combopane?1:0);
1101 }
1102 reload_zq_gui();
1103 }
1104 void toggle_compact_sqr_mode()
1105 {
1106 compact_square_panels = !compact_square_panels;
1107 zc_set_config("ZQ_GUI","square_panels_compact",compact_square_panels?1:0);
1108 reload_zq_gui();
1109 }
1110 void cycle_compact_sqr(bool down)
1111 {
1112 if(!(is_compact && compact_square_panels))
1113 return;
1114 static const int num_panels = 3;
1115 if(down)
1116 compact_active_panel = (compact_active_panel+1)%num_panels;
1117 else
1118 compact_active_panel = (compact_active_panel-1+num_panels)%num_panels;
1119 reload_zq_gui();
1120 }
1121 void toggle_favzoom_mode()
1122 {
1123 if(is_compact)
1124 {
1125 compact_zoomed_fav = !compact_zoomed_fav;
1126 zc_set_config("ZQ_GUI","zoom_fav_compact",compact_zoomed_fav?1:0);
1127 }
1128 else
1129 {
1130 large_zoomed_fav = !large_zoomed_fav;
1131 zc_set_config("ZQ_GUI","zoom_fav_large",large_zoomed_fav?1:0);
1132 }
1133 reload_zq_gui();
1134 }
1135 void toggle_cmdzoom_mode()
1136 {
1137 if(is_compact)
1138 {
1139 compact_zoomed_cmd = !compact_zoomed_cmd;
1140 zc_set_config("ZQ_GUI","zoom_cmd_compact",compact_zoomed_cmd?1:0);
1141 }
1142 else
1143 {
1144 large_zoomed_cmd = !large_zoomed_cmd;
1145 zc_set_config("ZQ_GUI","zoom_cmd_large",large_zoomed_cmd?1:0);
1146 }
1147 reload_zq_gui();
1148 }
1149
1150 enum
1151 {
1152 MENUID_FILE_SAVE,
1153 MENUID_FILE_SAVEAS,
1154 MENUID_FILE_REVERT,
1155 };
1156
1157
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu file_menu
1158 156 {
1159
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&New", do_NewQuest },
1160
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Open", do_OpenQuest },
1161
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Recent", &recent_menu },
1162
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1163
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Save", onSave, MENUID_FILE_SAVE },
1164
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Save &as...", onSaveAs, MENUID_FILE_SAVEAS },
1165
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Revert", onRevert, MENUID_FILE_REVERT },
1166
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1167
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Import", &import_menu },
1168
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Export", &export_menu },
1169 #ifndef __EMSCRIPTEN__
1170
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1171
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "E&xit", handle_quit },
1172 #endif
1173 };
1174
1175 enum
1176 {
1177 MENUID_MAPS_NEXT,
1178 MENUID_MAPS_PREV,
1179 };
1180
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu maps_menu
1181 72 {
1182
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Goto Map...", onGotoMap },
1183
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Next Map", onIncMap, MENUID_MAPS_NEXT },
1184
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Previous Map", onDecMap, MENUID_MAPS_PREV },
1185
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1186
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "D&elete Map", onDeleteMap },
1187 };
1188
1189
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu misc_menu
1190 120 {
1191
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "S&ubscreens", onEditSubscreens },
1192
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Shop Types", onShopTypes },
1193
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bottle Types", onBottleTypes },
1194
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Bottle S&hop Types", onBottleShopTypes },
1195
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Info Types", onInfoTypes },
1196
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warp Rings", onWarpRings },
1197
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Triforce Pieces", onTriPieces },
1198
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&End String", onEndString },
1199
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Item &Drop Sets", onItemDropSets },
1200 };
1201
1202
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu spr_menu
1203 48 {
1204
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onCustomWpns },
1205
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1206
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Misc Sprites", onMiscSprites },
1207 };
1208
1209
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu colors_menu
1210 48 {
1211
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Main ", onColors_Main },
1212
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Levels ", onColors_Levels },
1213
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", onColors_Sprites },
1214 };
1215
1216
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu defs_menu
1217 108 {
1218
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes", onDefault_Pals },
1219
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onDefault_Tiles },
1220
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onDefault_Combos },
1221
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onDefault_Items },
1222
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onDefault_Guys },
1223
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprite Data", onDefault_Weapons },
1224
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map Styles", onDefault_MapStyles },
1225
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onDefault_SFX },
1226 };
1227
1228 int32_t onEditComboAlias();
1229 int32_t onEditComboPool();
1230 int32_t onEditAutoCombo();
1231
1232
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu graphics_menu
1233 120 {
1234
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palettes ", &colors_menu },
1235
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Sprites ", &spr_menu },
1236
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combos", onCombos },
1237
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tiles", onTiles },
1238
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Game icons", onIcons },
1239
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc co&lors", onMiscColors },
1240
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Map styles", onMapStyles },
1241
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Door Combo Sets", onDoorCombos },
1242
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Aliases", onEditComboAlias },
1243 };
1244
1245
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu audio_menu
1246 48 {
1247
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "SF&X Data", onSelectSFX },
1248
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&MIDIs", onMidis },
1249
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Mis&c SFX", onMiscSFX },
1250 };
1251
1252 void set_rules(byte* newrules);
1253
1254 void call_testqst_dialog();
1255 int32_t onTestQst()
1256 {
1257 call_testqst_dialog();
1258 return D_O_K;
1259 }
1260
1261 int32_t onRulesDlg()
1262 {
1263 call_qr_dialog(21, set_rules);
1264 return D_O_K;
1265 }
1266
1267 int32_t onRulesSearch()
1268 {
1269 call_qrsearch_dialog(set_rules);
1270 return D_O_K;
1271 }
1272
1273 int32_t onZScriptSettings()
1274 {
1275 ScriptRulesDialog(quest_rules, 17, [](byte* newrules)
1276 {
1277 saved = false;
1278 memcpy(quest_rules, newrules, QR_SZ);
1279 unpack_qrs();
1280 }).show();
1281 return D_O_K;
1282 }
1283
1284 void call_zinf_dlg();
1285 int32_t onZInfo()
1286 {
1287 call_zinf_dlg();
1288 return D_O_K;
1289 }
1290
1291
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_menu
1292 204 {
1293
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options ", onRulesDlg },
1294
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Test", onTestQst },
1295
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Items", onCustomItems },
1296
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Ene&mies", onCustomEnemies },
1297
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hero", onCustomHero },
1298
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Strings", onStrings },
1299
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&DMaps", onDmaps },
1300
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Regions", onRegions },
1301
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "I&nit Data", onInit },
1302
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Misc D&ata ", &misc_menu },
1303
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZInfo", onZInfo },
1304
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1305
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Graphics ", &graphics_menu },
1306
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "A&udio ", &audio_menu },
1307
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1308
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "De&faults ", &defs_menu },
1309 };
1310
1311
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_menu
1312 36 {
1313
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &To All", onPasteToAll },
1314
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &All To All", onPasteAllToAll },
1315 };
1316
1317
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_item_menu
1318 156 {
1319
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undercombo", onPasteUnderCombo },
1320
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Secret Combos", onPasteSecretCombos },
1321
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onPasteFFCombos },
1322
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Screen &Data", onPasteScreenData },
1323
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps", onPasteWarps },
1324
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Warp &Return", onPasteWarpLocations },
1325
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onPasteEnemies },
1326
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Room &Type Data", onPasteRoom },
1327
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Guy/String", onPasteGuy },
1328
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Doo&rs", onPasteDoors },
1329
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Layers", onPasteLayers },
1330
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onPastePalette },
1331 };
1332
1333 enum
1334 {
1335 MENUID_EDIT_UNDO,
1336 MENUID_EDIT_REDO,
1337 MENUID_EDIT_COPY,
1338 MENUID_EDIT_PASTE,
1339 MENUID_EDIT_PASTEALL,
1340 MENUID_EDIT_ADVPASTE,
1341 MENUID_EDIT_SPECPASTE,
1342 MENUID_EDIT_DELETE,
1343 };
1344
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu edit_menu
1345 132 {
1346
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Undo", onUndo, MENUID_EDIT_UNDO },
1347
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Redo", onRedo, MENUID_EDIT_REDO },
1348
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Copy", onCopy, MENUID_EDIT_COPY },
1349
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Paste", onPaste, MENUID_EDIT_PASTE },
1350
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste A&ll", onPasteAll, MENUID_EDIT_PASTEALL },
1351
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Adv. Paste ", &paste_menu, MENUID_EDIT_ADVPASTE },
1352
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste &Spec. ", &paste_item_menu, MENUID_EDIT_SPECPASTE },
1353
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Delete", onDelete, MENUID_EDIT_DELETE },
1354
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1355
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maps ", &maps_menu },
1356 };
1357
1358
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu drawing_mode_menu
1359 60 {
1360
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Normal", onDrawingModeNormal, dm_normal },
1361
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Alias", onDrawingModeAlias, dm_alias },
1362
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pool", onDrawingModePool, dm_cpool },
1363
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Auto Combo", onDrawingModeAuto, dm_auto },
1364 };
1365
1366
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu integrity_check_menu
1367 48 {
1368
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&All ", onIntegrityCheckAll },
1369
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screens ", onIntegrityCheckRooms },
1370
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Warps ", onIntegrityCheckWarps },
1371 };
1372
1373
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu quest_reports_menu
1374 108 {
1375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Bugged Next-> Combo Locations", onBuggedNextComboLocationReport },
1376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Locations", onComboLocationReport },
1377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Combo Type Locations", onComboTypeLocationReport },
1378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemy Locations", onEnemyLocationReport },
1379
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item Locations", onItemLocationReport },
1380
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Script Locations", onScriptLocationReport },
1381
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&What Links Here", onWhatWarpsReport },
1382
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "In&tegrity Check ", &integrity_check_menu },
1383 };
1384
1385 int32_t onPalFix();
1386 int32_t onPitFix();
1387 int32_t onStrFix()
1388 {
1389 if(get_qr(qr_OLD_STRING_EDITOR_MARGINS))
1390 {
1391 AlertDialog("Fix: Old Margins",
1392 "Fixing margins may cause strings that used to spill outside the textbox"
1393 " to instead be cut off. Are you sure?",
1394 [&](bool ret,bool)
1395 {
1396 if(ret)
1397 {
1398 set_qr(qr_OLD_STRING_EDITOR_MARGINS, 0);
1399 saved = false;
1400 }
1401 }).show();
1402 }
1403 if(get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT))
1404 {
1405 AlertDialog("Fix: Old Frame Size",
1406 "This will fix the frame size of all strings. No visual changes should occur,"
1407 " as the string width/height will be fixed, but the compat QR will also be unchecked.",
1408 [&](bool ret,bool)
1409 {
1410 if(ret)
1411 {
1412 for(auto q = 0; q < msg_count; ++q)
1413 {
1414 MsgStrings[q].w += 16;
1415 MsgStrings[q].h += 16;
1416 }
1417 set_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT, 0);
1418 saved = false;
1419 }
1420 }).show();
1421 }
1422 return D_O_K;
1423 }
1424
1425 int32_t onRemoveOldArrivalSquare();
1426 enum
1427 {
1428 MENUID_FIXTOOL_OLDSTRING,
1429 };
1430
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fixtools_menu
1431 96 {
1432
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Color Set Fix", onCSetFix },
1433
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Liquid Solidity Fix", onWaterSolidity },
1434
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Effect Square Fix", onEffectFix },
1435
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Level Palette Fix", onPalFix },
1436
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Pit and Liquid Damage Fix", onPitFix },
1437
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Old Strings Fix", onStrFix, MENUID_FIXTOOL_OLDSTRING },
1438
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Green Arrival Square Fix", onRemoveOldArrivalSquare },
1439 };
1440
1441
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tool_menu
1442 132 {
1443
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Combo &Flags", onFlags, nullopt, MFL_EXIT_PRE_PROC },
1444
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fix &Tools ", &fixtools_menu },
1445
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&NES Dungeon Template", onTemplate },
1446
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Apply Template to All", onReTemplate },
1447
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1448
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Preview Mode", onPreviewMode },
1449
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Drawing &Mode ", &drawing_mode_menu },
1450
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1451
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Combos Used", onUsedCombos },
1452
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Reports ", &quest_reports_menu },
1453 };
1454
1455 int32_t onLayer3BG()
1456 {
1457 ViewLayer3BG = ViewLayer3BG ? 0 : 1;
1458 zc_set_config("zquest","layer3_bg",ViewLayer3BG);
1459 return D_O_K;
1460 }
1461 int32_t onLayer2BG()
1462 {
1463 ViewLayer2BG = ViewLayer2BG ? 0 : 1;
1464 zc_set_config("zquest","layer2_bg",ViewLayer2BG);
1465 return D_O_K;
1466 }
1467 int onGridToggle();
1468 enum
1469 {
1470 MENUID_VIEW_WALKABILITY,
1471 MENUID_VIEW_FLAGS,
1472 MENUID_VIEW_CSET,
1473 MENUID_VIEW_TYPES,
1474 MENUID_VIEW_INFO,
1475 MENUID_VIEW_SQUARES,
1476 MENUID_VIEW_FFCS,
1477 MENUID_VIEW_SCRIPTNAMES,
1478 MENUID_VIEW_GRID,
1479 MENUID_VIEW_SCREENGRID,
1480 MENUID_VIEW_REGIONGRID,
1481 MENUID_VIEW_CURSCROUTLINE,
1482 MENUID_VIEW_DARKNESS,
1483 MENUID_VIEW_L2BG,
1484 MENUID_VIEW_L3BG,
1485 MENUID_VIEW_LAYERHIGHLIGHT,
1486 };
1487
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 NewMenu view_menu
1488 252 {
1489
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Map...", onViewMap },
1490
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "View &Palette", onShowPal },
1491
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1492
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Walkability", onShowWalkability, MENUID_VIEW_WALKABILITY },
1493
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Flags", onShowFlags, MENUID_VIEW_FLAGS },
1494
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &CSets", onShowCSet, MENUID_VIEW_CSET },
1495
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Types", onShowCType, MENUID_VIEW_TYPES },
1496
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1497
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen &Info", onToggleShowInfo, MENUID_VIEW_INFO },
1498
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Squares", onToggleShowSquares, MENUID_VIEW_SQUARES },
1499
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show FFCs", onToggleShowFFCs, MENUID_VIEW_FFCS },
1500
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Script &Names", onToggleShowScripts, MENUID_VIEW_SCRIPTNAMES },
1501
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Grid", onGridToggle, MENUID_VIEW_GRID },
1502
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Screen G&rid", onToggleScreenGrid, MENUID_VIEW_SCREENGRID },
1503
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Region Grid", onToggleRegionGrid, MENUID_VIEW_REGIONGRID },
1504
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show Current Screen Outline", onToggleCurrentScreenOutline, MENUID_VIEW_CURSCROUTLINE },
1505
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Show &Darkness", onShowDarkness, MENUID_VIEW_DARKNESS },
1506
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 2 is Background", onLayer2BG, MENUID_VIEW_L2BG },
1507
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Layer 3 is Background", onLayer3BG, MENUID_VIEW_L3BG },
1508
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Highlight Current Layer", onToggleHighlightLayer, MENUID_VIEW_LAYERHIGHLIGHT },
1509 };
1510
1511 11 void set_rules(byte* newrules)
1512 {
1513 11 saved = false;
1514
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(newrules != quest_rules)
1515 memcpy(quest_rules, newrules, QR_SZ);
1516 11 unpack_qrs();
1517
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(!get_qr(qr_ALLOW_EDITING_COMBO_0))
1518 {
1519 2 combobuf[0].walk = 0xF0;
1520 2 combobuf[0].type = 0;
1521 2 combobuf[0].flag = 0;
1522 2 }
1523
1524 // For 2.50.0 and 2.50.1
1525
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2 times.
11 if(get_qr(qr_VERYFASTSCROLLING))
1526 2 set_qr(qr_FASTDNGN, 1);
1527 11 }
1528
1529 int32_t onSelectFFCombo();
1530
1531 void onScreenNotes()
1532 {
1533 edit_screen_notes(Map.CurrScr(), Map.getCurrMap(), Map.getCurrScr());
1534 }
1535
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu data_menu
1536 216 {
1537
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen Data", onScrData },
1538
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Freeform Combos", onSelectFFCombo },
1539
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "La&yers", onLayers },
1540
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tile Warp", onTileWarp },
1541
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Side &Warp", onSideWarp },
1542
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Secret &Combos", onSecretCombo },
1543
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Under Combo", onUnderCombo },
1544
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Doors", onDoors },
1545
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Maze Path", onPath },
1546
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1547
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Item", onItem },
1548
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Enemies", onEnemies },
1549
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Palette", onScreenPalette },
1550
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1551
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Room Data", onRoom },
1552
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Notes", onScreenNotes },
1553
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Browse Notes", browse_screen_notes },
1554 };
1555
1556
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu tunes_menu
1557 252 {
1558
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ZC Forever", playZCForever },
1559
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Wind Fish", playTune1 },
1560
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Overworld", playTune2 },
1561
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Hyrule Castle", playTune3 },
1562
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Lost Woods", playTune4 },
1563
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Great Sea", playTune5 },
1564
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "East Hyrule", playTune6 },
1565
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dancing Dragon", playTune7 },
1566
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Stone Tower", playTune8 },
1567
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Villages", playTune9 },
1568
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Swamp + Desert", playTune10 },
1569
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Outset Island", playTune11 },
1570
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Kakariko Village", playTune12 },
1571
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clock Town", playTune13 },
1572
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Temple", playTune14 },
1573
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dark World", playTune15 },
1574
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Dragon Roost", playTune16 },
1575
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Horse Race", playTune17 },
1576
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Credits", playTune18 },
1577
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Zelda's Lullaby", playTune19 },
1578 };
1579
1580 enum
1581 {
1582 MENUID_MEDIA_TUNES,
1583 MENUID_MEDIA_PLAYMUSIC,
1584 MENUID_MEDIA_CHANGETRACK,
1585 };
1586
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu media_menu
1587 60 {
1588
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Ambient Music ", &tunes_menu, MENUID_MEDIA_TUNES },
1589
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Play music", playMusic, MENUID_MEDIA_PLAYMUSIC },
1590
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Change track", changeTrack, MENUID_MEDIA_CHANGETRACK },
1591
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Stop tunes", stopMusic },
1592 };
1593
1594 enum
1595 {
1596 MENUID_ETC_VIDMODE,
1597 MENUID_ETC_FULLSCREEN,
1598 MENUID_ETC_DEBUG_CONSOLE,
1599 };
1600
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu etc_menu
1601 192 {
1602
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Help", &zq_help_menu },
1603
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&About", onAbout },
1604
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Video Mode", onZQVidMode, MENUID_ETC_VIDMODE },
1605
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Options...", onOptions },
1606
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Hotkeys...", do_zq_hotkey_dialog },
1607
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&List Hotkeys...", do_zq_list_hotkeys_dialog },
1608
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Fullscreen", onFullScreen, MENUID_ETC_FULLSCREEN },
1609
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1610
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View Pic...", onViewPic },
1611
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Media", &media_menu },
1612
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1613
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Debug Console", toggleConsole, MENUID_ETC_DEBUG_CONSOLE },
1614
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Clear Quest Filepath", onClearQuestFilepath },
1615
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Take ZQ Snapshot", onMenuSnapshot },
1616
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Take &Screen Snapshot", onMapscrSnapshot },
1617 };
1618
1619
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu zscript_menu
1620 60 {
1621
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Compile &ZScript...", onCompileScript },
1622
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 {},
1623
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Compiler Settings", onZScriptCompilerSettings },
1624
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest Script Settings", onZScriptSettings },
1625 };
1626
1627 void set_console_state()
1628 {
1629 etc_menu.select_uid(MENUID_ETC_DEBUG_CONSOLE, console_is_open);
1630 }
1631
1632
3/16
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
12 NewMenu foo_menu{{"FOO",[](){InfoDialog("PLACEHOLDER","THIS IS A PLACEHOLDER").show();}}};
1633
1634
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 TopMenu the_menu
1635 108 {
1636
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&File", &file_menu },
1637
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Quest", &quest_menu },
1638
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Edit", &edit_menu },
1639
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&View", &view_menu },
1640
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Tools", &tool_menu },
1641
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&Screen", &data_menu },
1642
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "&ZScript", &zscript_menu },
1643
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Et&C", &etc_menu },
1644 };
1645
1646 void rebuild_trans_table();
1647 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal,
1648 int32_t *px2, int32_t *py2, double *scale, bool isviewingmap, bool skipmenu = false);
1649
1650 int32_t onResetTransparency()
1651 {
1652 restore_mouse();
1653 rebuild_trans_table();
1654 jwin_alert("Notice","Translucency Table Rebuilt",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
1655
1656 refresh(rALL);
1657 return D_O_K;
1658 }
1659
1660 int32_t onFullScreen()
1661 {
1662 get_palette(RAMpal);
1663 bool windowed=is_windowed_mode()!=0;
1664 all_toggle_fullscreen(windowed);
1665
1666 gui_mouse_focus=0;
1667 gui_bg_color=jwin_pal[jcBOX];
1668 gui_fg_color=jwin_pal[jcBOXFG];
1669 MouseSprite::set(ZQM_NORMAL);
1670 zc_set_palette(RAMpal);
1671 position_mouse(zq_screen_w/2,zq_screen_h/2);
1672 set_display_switch_mode(SWITCH_BACKGROUND);
1673 set_display_switch_callback(SWITCH_OUT, switch_out);
1674 set_display_switch_callback(SWITCH_IN, switch_in);
1675 zc_set_config("zquest","fullscreen", is_windowed_mode() ? 0 : 1);
1676 return D_REDRAW;
1677 }
1678
1679 int32_t onEnter()
1680 {
1681 if(key[KEY_ALT]||key[KEY_ALTGR])
1682 {
1683 return onFullScreen();
1684 }
1685
1686 return D_O_K;
1687 }
1688
1689 //PROC, x, y, w, h, fg, bg, key, flags, d1, d2, *dp, *dp2, *dp3
1690
1691 //*text, (*proc), *child, flags, *dp
1692
1693 void run_zq_frame();
1694 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c);
1695
1696
1697 /*int32_t onY()
1698 {
1699 return D_O_K;
1700 }*/
1701
1702 int32_t onToggleGrid(bool color)
1703 {
1704 if(color)
1705 {
1706 GridColor=(GridColor+8)%16;
1707 zc_set_config("zquest", "grid_color", GridColor);
1708 }
1709 else
1710 {
1711 ShowGrid=!ShowGrid;
1712 zc_set_config("zquest","show_grid",ShowGrid);
1713 }
1714
1715 return D_O_K;
1716 }
1717
1718 int onGridToggle()
1719 {
1720 return onToggleGrid(CHECK_CTRL_CMD);
1721 }
1722
1723 int32_t onToggleScreenGrid()
1724 {
1725 ShowScreenGrid=!ShowScreenGrid;
1726 zc_set_config("zquest","show_screen_grid",ShowScreenGrid);
1727 return D_O_K;
1728 }
1729
1730 int32_t onToggleRegionGrid()
1731 {
1732 ShowRegionGrid=!ShowRegionGrid;
1733 zc_set_config("zquest","show_region_grid",ShowRegionGrid);
1734 return D_O_K;
1735 }
1736
1737 int32_t onToggleCurrentScreenOutline()
1738 {
1739 ShowCurScreenOutline=!ShowCurScreenOutline;
1740 zc_set_config("zquest","show_current_screen_outline",ShowCurScreenOutline);
1741 return D_O_K;
1742 }
1743
1744 int32_t onToggleShowScripts()
1745 {
1746 ShowFFScripts=!ShowFFScripts;
1747 zc_set_config("zquest","showffscripts",ShowFFScripts);
1748 return D_O_K;
1749 }
1750
1751 int32_t onToggleShowFFCs()
1752 {
1753 ShowFFCs=!ShowFFCs;
1754 zc_set_config("zquest","showffcs",ShowFFCs);
1755 return D_O_K;
1756 }
1757
1758 int32_t onToggleShowSquares()
1759 {
1760 ShowSquares=!ShowSquares;
1761 zc_set_config("zquest","showsquares",ShowSquares);
1762 return D_O_K;
1763 }
1764
1765 int32_t onToggleShowInfo()
1766 {
1767 ShowInfo=!ShowInfo;
1768 zc_set_config("zquest","showinfo",ShowInfo);
1769 return D_O_K;
1770 }
1771
1772 int32_t onToggleHighlightLayer()
1773 {
1774 ActiveLayerHighlight = ActiveLayerHighlight ? 0 : 1;
1775 zc_set_config("zquest","hl_active_lyr",ActiveLayerHighlight);
1776 return D_O_K;
1777 }
1778
1779 int onKeySlash()
1780 {
1781 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1782 {
1783 onAbout();
1784 }
1785 return D_O_K;
1786 }
1787
1788 int onAKey()
1789 {
1790 if(prv_mode)
1791 Map.set_prvadvance(1);
1792 return D_O_K;
1793 }
1794
1795 int onReloadPreview()
1796 {
1797 if(prv_mode)
1798 {
1799 Map.set_prvscr(Map.get_prv_map(), Map.get_prv_scr());
1800 Map.set_prvcmb(0);
1801 }
1802 return D_O_K;
1803 }
1804 int onSecretsPreview()
1805 {
1806 if(prv_mode)
1807 {
1808 Map.prv_secrets(false);
1809 refresh(rALL);
1810 }
1811 return D_O_K;
1812 }
1813
1814 int onSKey()
1815 {
1816 if(CHECK_CTRL_CMD)
1817 {
1818 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1819 {
1820 onSaveAs();
1821 }
1822 else
1823 {
1824 if(!saved)
1825 onSave();
1826 }
1827 }
1828 else if(prv_mode)
1829 {
1830 Map.prv_secrets(false);
1831 refresh(rALL);
1832 }
1833 else onStrings();
1834 return D_O_K;
1835 }
1836 int onSetNewLayer(int newlayer)
1837 {
1838 CurrentLayer = newlayer;
1839 refresh(rALL);
1840 return D_O_K;
1841 }
1842 void lpal_dsa()
1843 {
1844 info_dsa("Level Palette Shortcuts",
1845 "You currently have level palette shortcuts disabled."
1846 " These can be re-enabled in 'Etc->Options', on the toggle 'Disable Level Palette Shortcuts'.",
1847 "dsa_lpal");
1848 }
1849 int onScreenLPal(int lpal)
1850 {
1851 if(DisableLPalShortcuts)
1852 {
1853 lpal_dsa();
1854 return D_O_K;
1855 }
1856 saved=false;
1857 Map.setcolor(lpal);
1858 refresh(rSCRMAP);
1859 return D_O_K;
1860 }
1861
1862 int32_t onPressEsc()
1863 {
1864 if(zoomed_minimap)
1865 mmap_set_zoom(false);
1866 else return onExit();
1867 return D_O_K;
1868 }
1869
1870 static DIALOG dialogs[] =
1871 {
1872 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
1873 { d_nbmenu_proc, 0, 0, 0, 13, 0, 0, 0, D_USER, 0, 0, (void *) &the_menu, NULL, NULL },
1874 { d_zq_hotkey_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1875
1876 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
1877 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_ESC, 0, (void *) onPressEsc, NULL, NULL },
1878 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, (void *) onUsedCombos, NULL, NULL },
1879 { d_vsync_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1880 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1881 };
1882
1883
1884 int32_t onDecColour()
1885 {
1886 if ( CHECK_CTRL_CMD )
1887 {
1888 return onDecScrPal16();
1889 }
1890
1891 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1892 {
1893 return onDecScrPal();
1894 }
1895
1896 else
1897 {
1898 return onDecreaseCSet();
1899 }
1900 }
1901
1902 int32_t onIncColour()
1903 {
1904
1905 if ( CHECK_CTRL_CMD )
1906 {
1907 return onIncScrPal16();
1908 }
1909
1910 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1911 {
1912 return onIncScrPal();
1913 }
1914
1915 else
1916 {
1917 return onIncreaseCSet();
1918 }
1919 }
1920
1921 static DIALOG getnum_dlg[] =
1922 {
1923 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1924 12 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
1925 12 { jwin_rtext_proc, 114, 104+4, 48, 8, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) "Value:", NULL, NULL },
1926 12 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
1927 12 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
1928 12 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1929 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1930 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1931 };
1932
1933 int32_t getnumber(const char *prompt,int32_t initialval)
1934 {
1935 cancelgetnum=true;
1936 char buf[20];
1937 sprintf(buf,"%d",initialval);
1938 getnum_dlg[0].dp=(void *)prompt;
1939 getnum_dlg[0].dp2=get_zc_font(font_lfont);
1940 getnum_dlg[2].dp=(void *)buf;
1941
1942 large_dialog(getnum_dlg);
1943
1944 int32_t ret=do_zqdialog(getnum_dlg,2);
1945
1946 if(ret!=0&&ret!=4)
1947 {
1948 cancelgetnum=false;
1949 }
1950
1951 if(ret==3)
1952 return atoi(buf);
1953
1954 return initialval;
1955 }
1956
1957 static DIALOG save_tiles_dlg[] =
1958 {
1959 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1960
1961
1962 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Tile Pack", NULL, NULL },
1963 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1964 //for future tabs
1965 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1966 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1967 //4
1968 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
1969 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1970 //6
1971 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1972 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1973 //8
1974 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
1975 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1976 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1977 };
1978
1979
1980 void savesometiles(const char *prompt,int32_t initialval)
1981 {
1982
1983 char firsttile[8], tilecount[8];
1984 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1985 sprintf(firsttile,"%d",0);
1986 sprintf(tilecount,"%d",1);
1987 //int32_t ret;
1988
1989
1990
1991 save_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1992
1993 sprintf(firsttile,"%d",0);
1994 sprintf(tilecount,"%d",1);
1995
1996 save_tiles_dlg[5].dp = firsttile;
1997 save_tiles_dlg[7].dp = tilecount;
1998
1999 large_dialog(save_tiles_dlg);
2000
2001 int32_t ret = do_zqdialog(save_tiles_dlg,-1);
2002 jwin_center_dialog(save_tiles_dlg);
2003
2004 if(ret == 8)
2005 {
2006 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2007 the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2008 if(prompt_for_new_file_compat("Save ZTILE(.ztile)", "ztile", NULL,datapath,false))
2009 {
2010 char name[PATH_MAX];
2011 extract_name(temppath,name,FILENAMEALL);
2012 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2013 if(f)
2014 {
2015 writetilefile(f,first_tile_id,the_tile_count);
2016 pack_fclose(f);
2017 char tmpbuf[PATH_MAX+20]={0};
2018 sprintf(tmpbuf,"Saved %s",name);
2019 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2020 }
2021 }
2022 }
2023 }
2024
2025 static DIALOG read_tiles_dlg[] =
2026 {
2027 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2028
2029
2030 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Tilepack To:", NULL, NULL },
2031 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2032 //for future tabs
2033 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2034 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2035 //4
2036 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2037 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2038 //6
2039 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2040 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2041 //8
2042 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2043 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2044 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2045 };
2046
2047
2048 void writesometiles_to(const char *prompt,int32_t initialval)
2049 {
2050
2051 char firsttile[8];;
2052 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2053 sprintf(firsttile,"%d",0);
2054 //int32_t ret;
2055
2056
2057
2058 read_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
2059
2060 sprintf(firsttile,"%d",0);
2061 //sprintf(tilecount,"%d",1);
2062
2063 read_tiles_dlg[5].dp = firsttile;
2064
2065 large_dialog(read_tiles_dlg);
2066
2067 int32_t ret = do_zqdialog(read_tiles_dlg,-1);
2068 jwin_center_dialog(read_tiles_dlg);
2069
2070 if(ret == 8)
2071 {
2072 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2073 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2074 if(prompt_for_existing_file_compat("Load ZTILE(.ztile)", "ztile", NULL,datapath,false))
2075 {
2076
2077 char name[256];
2078 extract_name(temppath,name,FILENAMEALL);
2079 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2080 if(f)
2081 {
2082
2083 if (!readtilefile_to_location(f,first_tile_id))
2084 {
2085 al_trace("Could not read from .ztile packfile %s\n", name);
2086 jwin_alert("ZTILE File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2087 }
2088 else
2089 {
2090 jwin_alert("ZTILE File: Success!","Loaded the source tiles to your tile sheets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2091 }
2092 pack_fclose(f);
2093 }
2094 }
2095 }
2096 }
2097
2098
2099 static DIALOG save_combofiles_dlg[] =
2100 {
2101 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2102
2103
2104 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Pack", NULL, NULL },
2105 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2106 //for future tabs
2107 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2108 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2109 //4
2110 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2111 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2112 //6
2113 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2114 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2115 //8
2116 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2117 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2118 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2119 };
2120
2121
2122 void savesomecombos(const char *prompt,int32_t initialval)
2123 {
2124
2125 char firsttile[8], tilecount[8];
2126 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2127 sprintf(firsttile,"%d",0);
2128 sprintf(tilecount,"%d",1);
2129 //int32_t ret;
2130
2131
2132
2133 save_combofiles_dlg[0].dp2 = get_zc_font(font_lfont);
2134
2135 sprintf(firsttile,"%d",0);
2136 sprintf(tilecount,"%d",1);
2137
2138 save_combofiles_dlg[5].dp = firsttile;
2139 save_combofiles_dlg[7].dp = tilecount;
2140
2141 large_dialog(save_combofiles_dlg);
2142
2143 int32_t ret = do_zqdialog(save_combofiles_dlg,-1);
2144 jwin_center_dialog(save_combofiles_dlg);
2145
2146 if(ret == 8)
2147 {
2148 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2149 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOS-1)-first_tile_id);
2150 if(prompt_for_new_file_compat("Save ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2151 {
2152 char name[PATH_MAX];
2153 extract_name(temppath,name,FILENAMEALL);
2154 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2155 if(f)
2156 {
2157 writecombofile(f,first_tile_id,the_tile_count);
2158 pack_fclose(f);
2159 char tmpbuf[PATH_MAX+20]={0};
2160 sprintf(tmpbuf,"Saved %s",name);
2161 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2162 }
2163 }
2164 }
2165 }
2166
2167
2168 static DIALOG load_comboset_dlg[] =
2169 {
2170 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2171
2172
2173 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Set (Range)", NULL, NULL },
2174 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2175 //for future tabs
2176 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2177 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2178 //4
2179 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2180 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2181 //6
2182 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2183 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2184 //8
2185 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2186 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2187 { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2188
2189 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2190 };
2191
2192 void writesomecombos(const char *prompt,int32_t initialval)
2193 {
2194
2195 char firsttile[8];
2196 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2197 sprintf(firsttile,"%d",0);
2198 //int32_t ret;
2199
2200
2201
2202 load_comboset_dlg[0].dp2 = get_zc_font(font_lfont);
2203
2204 sprintf(firsttile,"%d",0);
2205 //sprintf(tilecount,"%d",1);
2206
2207 load_comboset_dlg[5].dp = firsttile;
2208
2209 byte nooverwrite = 0;
2210
2211
2212 large_dialog(load_comboset_dlg);
2213
2214 int32_t ret = do_zqdialog(load_comboset_dlg,-1);
2215 jwin_center_dialog(load_comboset_dlg);
2216
2217 if(ret == 8)
2218 {
2219 if (load_comboset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2220
2221 al_trace("Nooverwrite is: %d\n", nooverwrite);
2222 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2223 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2224 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2225 {
2226 char name[256];
2227 extract_name(temppath,name,FILENAMEALL);
2228 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2229 if(f)
2230 {
2231
2232 if (!readcombofile(f,first_tile_id,nooverwrite))
2233 {
2234 al_trace("Could not read from .zcombo packfile %s\n", name);
2235 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2236 }
2237 else
2238 {
2239 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2240 saved=false;
2241 }
2242 pack_fclose(f);
2243 }
2244
2245 }
2246 }
2247 }
2248
2249 static DIALOG load_combopack_dlg[] =
2250 {
2251 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2252
2253
2254 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import Full Combo Package 1:1", NULL, NULL },
2255 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2256 //for future tabs
2257 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2258 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2259 //4
2260 { d_dummy_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2261 { d_dummy_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2262 //6
2263 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2264 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2265 //8
2266 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2267 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2268 { jwin_check_proc, 10, 42, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2269
2270 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2271 };
2272
2273 void loadcombopack(const char *prompt,int32_t initialval)
2274 {
2275
2276 char firsttile[8];
2277 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2278 sprintf(firsttile,"%d",0);
2279 //int32_t ret;
2280
2281
2282
2283 load_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2284
2285 sprintf(firsttile,"%d",0);
2286 //sprintf(tilecount,"%d",1);
2287
2288 load_combopack_dlg[5].dp = firsttile;
2289
2290 byte nooverwrite = 0;
2291
2292
2293 large_dialog(load_combopack_dlg);
2294
2295 int32_t ret = do_zqdialog(load_combopack_dlg,-1);
2296 jwin_center_dialog(load_combopack_dlg);
2297
2298 if(ret == 8)
2299 {
2300 if (load_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2301
2302 al_trace("Nooverwrite is: %d\n", nooverwrite);
2303 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2304 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2305 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2306 {
2307 char name[256];
2308 extract_name(temppath,name,FILENAMEALL);
2309 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2310 if(f)
2311 {
2312 //need dialogue here
2313 if (!readcombofile(f,0,nooverwrite))
2314 {
2315 al_trace("Could not read from .zcombo packfile %s\n", name);
2316 jwin_alert("ZCOMBO File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2317 }
2318 else
2319 {
2320 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2321 saved=false;
2322 }
2323 }
2324
2325 pack_fclose(f);
2326 }
2327 }
2328 }
2329
2330
2331 static DIALOG read_combopack_dlg[] =
2332 {
2333 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2334
2335
2336 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combos (Specific Dest)", NULL, NULL },
2337 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2338 //for future tabs
2339 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2340 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2341 //4
2342 { jwin_text_proc, 10, 24, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2343 { jwin_edit_proc, 55, 22, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2344 //6
2345 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2346 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2347 //8
2348 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2349 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2350 //10
2351 { jwin_check_proc, 10, 58, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2352 //11
2353 { jwin_text_proc, 10, 42, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Skip:", NULL, NULL },
2354 //12
2355 { jwin_edit_proc, 55, 40, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2356
2357 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2358 };
2359
2360
2361
2362 void writesomecombos_to(const char *prompt,int32_t initialval)
2363 {
2364
2365 char firsttile[8];
2366 char skiptile[8];
2367 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2368 sprintf(firsttile,"%d",0);
2369 //int32_t ret;
2370
2371
2372
2373 read_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2374
2375 sprintf(skiptile,"%d",0);
2376 //sprintf(tilecount,"%d",1);
2377
2378 read_combopack_dlg[5].dp = firsttile;
2379
2380 byte nooverwrite = 0;
2381 int32_t skipover = 0;
2382
2383 sprintf(skiptile,"%d",0);
2384 //sprintf(tilecount,"%d",1);
2385
2386 read_combopack_dlg[12].dp = skiptile;
2387
2388 large_dialog(read_combopack_dlg);
2389
2390 int32_t ret = do_zqdialog(read_combopack_dlg,-1);
2391 jwin_center_dialog(read_combopack_dlg);
2392
2393 if(ret == 8)
2394 {
2395 if (read_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2396
2397 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2398 skipover = vbound(atoi(skiptile), 0, (MAXCOMBOS-1));
2399 al_trace("skipover is: %d\n", skipover);
2400 //skipover = vbound(skipover, 0, (MAXCOMBOS-1-skipover));
2401 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2402 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2403 {
2404 char name[256];
2405 extract_name(temppath,name,FILENAMEALL);
2406 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2407 if(f)
2408 {
2409
2410 if (!readcombofile_to_location(f,first_tile_id,nooverwrite, skipover))
2411 {
2412 al_trace("Could not read from .zcombo packfile %s\n", name);
2413 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2414 }
2415 else
2416 {
2417 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2418 saved=false;
2419 }
2420 pack_fclose(f);
2421 }
2422
2423 }
2424 }
2425 }
2426
2427
2428
2429 static DIALOG save_dmaps_dlg[] =
2430 {
2431 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2432
2433
2434 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save DMaps (.zdmap)", NULL, NULL },
2435 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2436 //for future tabs
2437 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2438 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2439 //4
2440 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2441 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2442 //6
2443 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Last", NULL, NULL },
2444 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2445 //8
2446 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2447 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2448 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2449 };
2450
2451
2452 void savesomedmaps(const char *prompt,int32_t initialval)
2453 {
2454
2455 char firstdmap[8], lastdmap[8];
2456 int32_t first_dmap_id = 0; int32_t last_dmap_id = 0;
2457 sprintf(firstdmap,"%d",0);
2458 sprintf(lastdmap,"%d",1);
2459 //int32_t ret;
2460
2461
2462
2463 save_dmaps_dlg[0].dp2 = get_zc_font(font_lfont);
2464
2465 sprintf(firstdmap,"%d",0);
2466 sprintf(lastdmap,"%d",0);
2467
2468 save_dmaps_dlg[5].dp = firstdmap;
2469 save_dmaps_dlg[7].dp = lastdmap;
2470
2471 large_dialog(save_dmaps_dlg);
2472
2473 int32_t ret = do_zqdialog(save_dmaps_dlg,-1);
2474 jwin_center_dialog(save_dmaps_dlg);
2475
2476 if(ret == 8)
2477 {
2478 first_dmap_id = vbound(atoi(firstdmap), 0, MAXDMAPS-1);
2479 last_dmap_id = vbound(atoi(lastdmap), 0, MAXDMAPS-1);
2480
2481 if ( last_dmap_id < first_dmap_id )
2482 {
2483 int32_t swap = last_dmap_id;
2484 last_dmap_id = first_dmap_id;
2485 first_dmap_id = swap;
2486 }
2487 if(!prompt_for_new_file_compat("Export DMaps (.zdmap)","zdmap",NULL,datapath,false))
2488
2489
2490 saved=false;
2491
2492 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2493 if(f)
2494 {
2495 if(!writesomedmaps(f,first_dmap_id,last_dmap_id,MAXDMAPS))
2496 {
2497 char buf[PATH_MAX+20],name[PATH_MAX];
2498 extract_name(temppath,name,FILENAMEALL);
2499 sprintf(buf,"Unable to load %s",name);
2500 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2501 }
2502 else
2503 {
2504 char name[PATH_MAX];
2505 extract_name(temppath,name,FILENAMEALL);
2506 char tmpbuf[PATH_MAX+20]={0};
2507 sprintf(tmpbuf,"Saved %s",name);
2508 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2509 }
2510 }
2511 pack_fclose(f);
2512 }
2513 }
2514
2515 static DIALOG save_comboaliasfiles_dlg[] =
2516 {
2517 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2518
2519
2520 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Alias Pack", NULL, NULL },
2521 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2522 //for future tabs
2523 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2524 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2525 //4
2526 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2527 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2528 //6
2529 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2530 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2531 //8
2532 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2533 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2534 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2535 };
2536
2537
2538 void savesomecomboaliases(const char *prompt,int32_t initialval)
2539 {
2540
2541 char firsttile[8], tilecount[8];
2542 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2543 sprintf(firsttile,"%d",0);
2544 sprintf(tilecount,"%d",1);
2545 //int32_t ret;
2546
2547
2548
2549 save_comboaliasfiles_dlg[0].dp2 = get_zc_font(font_lfont);
2550
2551 sprintf(firsttile,"%d",0);
2552 sprintf(tilecount,"%d",1);
2553
2554 save_comboaliasfiles_dlg[5].dp = firsttile;
2555 save_comboaliasfiles_dlg[7].dp = tilecount;
2556
2557 large_dialog(save_comboaliasfiles_dlg);
2558
2559 int32_t ret = do_zqdialog(save_comboaliasfiles_dlg,-1);
2560 jwin_center_dialog(save_comboaliasfiles_dlg);
2561
2562 if(ret == 8)
2563 {
2564 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2565 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOALIASES-1)-first_tile_id);
2566 if(prompt_for_new_file_compat("Save ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2567 {
2568 char name[PATH_MAX];
2569 extract_name(temppath,name,FILENAMEALL);
2570 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2571 if(f)
2572 {
2573 writecomboaliasfile(f,first_tile_id,the_tile_count);
2574 pack_fclose(f);
2575 char tmpbuf[PATH_MAX+20]={0};
2576 sprintf(tmpbuf,"Saved %s",name);
2577 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2578 }
2579 }
2580 }
2581 }
2582
2583
2584 static DIALOG read_comboaliaspack_dlg[] =
2585 {
2586 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2587
2588
2589 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combo Pack To:", NULL, NULL },
2590 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2591 //for future tabs
2592 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2593 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2594 //4
2595 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2596 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2597 //6
2598 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2599 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2600 //8
2601 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2602 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2603 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2604 };
2605
2606
2607 void writesomecomboaliases_to(const char *prompt,int32_t initialval)
2608 {
2609
2610 char firsttile[8];;
2611 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2612 sprintf(firsttile,"%d",0);
2613 //int32_t ret;
2614
2615
2616
2617 read_comboaliaspack_dlg[0].dp2 = get_zc_font(font_lfont);
2618
2619 sprintf(firsttile,"%d",0);
2620 //sprintf(tilecount,"%d",1);
2621
2622 read_comboaliaspack_dlg[5].dp = firsttile;
2623
2624 large_dialog(read_comboaliaspack_dlg);
2625
2626 int32_t ret = do_zqdialog(read_comboaliaspack_dlg,-1);
2627 jwin_center_dialog(read_comboaliaspack_dlg);
2628
2629 if(ret == 8)
2630 {
2631 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2632 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2633 if(prompt_for_existing_file_compat("Load ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2634 {
2635 char name[256];
2636 extract_name(temppath,name,FILENAMEALL);
2637 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2638 if(f)
2639 {
2640
2641 if (!readcomboaliasfile_to_location(f,first_tile_id))
2642 {
2643 al_trace("Could not read from .zcombo packfile %s\n", name);
2644 jwin_alert("ZALIAS File: Error","Could not load the specified combo aliases.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2645 }
2646 else
2647 {
2648 jwin_alert("ZALIAS File: Success!","Loaded the source combos to your combo alias table!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2649 saved=false;
2650 }
2651 pack_fclose(f);
2652 }
2653 }
2654 }
2655 }
2656
2657
2658
2659
2660 //Doorsets
2661
2662 static DIALOG save_doorset_dlg[] =
2663 {
2664 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2665 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Doorset", NULL, NULL },
2666 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2667 //for future tabs
2668 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2669 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2670 //4
2671 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2672 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2673 //6
2674 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2675 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2676 //8
2677 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2678 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2679 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2680 };
2681
2682
2683 void do_exportdoorset(const char *prompt,int32_t initialval)
2684 {
2685 char firstdoor[8], doorct[8];
2686 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2687 sprintf(firstdoor,"%d",0);
2688 sprintf(doorct,"%d",1);
2689 //int32_t ret;
2690 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2691
2692 sprintf(firstdoor,"%d",0);
2693 sprintf(doorct,"%d",1);
2694
2695 save_doorset_dlg[5].dp = firstdoor;
2696 save_doorset_dlg[7].dp = doorct;
2697
2698 large_dialog(save_doorset_dlg);
2699
2700 int32_t ret = do_zqdialog(save_doorset_dlg,-1);
2701 jwin_center_dialog(save_doorset_dlg);
2702
2703 if(ret == 8) //OK
2704 {
2705 /* sanity bounds
2706 first_doorset_id = vbound(atoi(firstdoor), 0, (MAXCOMBOS-1));
2707 the_doorset_count = vbound(atoi(doorct), 1, (MAXCOMBOS-1)-first_doorset_id);
2708 */
2709 if(prompt_for_new_file_compat("Save ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2710 {
2711 char name[256];
2712 extract_name(temppath,name,FILENAMEALL);
2713 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2714 if(f)
2715 {
2716 writezdoorsets(f,first_doorset_id,the_doorset_count);
2717 pack_fclose(f);
2718 char tmpbuf[512]={0};
2719 sprintf(tmpbuf,"Saved %s",name);
2720 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2721 }
2722 }
2723 }
2724 }
2725
2726 static DIALOG load_doorset_dlg[] =
2727 {
2728 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2729 { jwin_win_proc, 0, 0, 120, 124, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Door Set (Range)", NULL, NULL },
2730 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2731 //for future tabs
2732 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2733 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2734 //4
2735 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2736 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2737 //6
2738 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2739 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2740 //8
2741 { jwin_button_proc, 15, 92, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2742 { jwin_button_proc, 69, 92, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2743 //10
2744 { jwin_text_proc, 10, 64, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Dest", NULL, NULL },
2745 { jwin_edit_proc, 55, 63, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2746 //8
2747
2748 // { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2749
2750 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2751 };
2752
2753 void do_importdoorset(const char *prompt,int32_t initialval)
2754 {
2755
2756 char firstdoor[8], doorct[8], destid[8];
2757 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2758 int32_t the_dest_id = 0;
2759 sprintf(firstdoor,"%d",0);
2760 sprintf(doorct,"%d",1);
2761 sprintf(destid,"%d",0);
2762 //int32_t ret;
2763
2764 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2765
2766 load_doorset_dlg[5].dp = firstdoor;
2767 load_doorset_dlg[7].dp = doorct;
2768 load_doorset_dlg[11].dp = destid;
2769
2770 byte nooverwrite = 0;
2771
2772 large_dialog(load_doorset_dlg);
2773
2774 int32_t ret = do_zqdialog(load_doorset_dlg,-1);
2775 jwin_center_dialog(load_doorset_dlg);
2776
2777 if(ret == 8) //OK
2778 {
2779 //if (load_doorset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2780
2781 //sanity bound
2782 first_doorset_id = vbound(atoi(firstdoor), 0, door_combo_set_count);
2783 the_doorset_count = vbound(atoi(doorct), 1, door_combo_set_count);
2784 the_dest_id = vbound(atoi(destid), 0, door_combo_set_count);
2785 if(prompt_for_existing_file_compat("Load ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2786 {
2787 char name[256];
2788 extract_name(temppath,name,FILENAMEALL);
2789 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2790 if(f)
2791 {
2792 int32_t ret = readzdoorsets(f,first_doorset_id,the_doorset_count, the_dest_id);
2793
2794 if (!ret)
2795 {
2796 al_trace("Could not read from .zdoors packfile %s\n", name);
2797 jwin_alert("ZDOORS File: Error","Could not load the specified doorsets.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2798 }
2799 else if ( ret == 1 )
2800 {
2801 jwin_alert("ZDOORS File: Success!","Loaded the source doorsets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2802 saved=false;
2803 }
2804 else if ( ret == 2 )
2805 {
2806 jwin_alert("ZDOORS File: Issue:","Targets exceed doorset count!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2807 saved=false;
2808 }
2809 pack_fclose(f);
2810 }
2811 }
2812 }
2813 }
2814
2815 int32_t gettilepagenumber(const char *prompt, int32_t initialval)
2816 {
2817 char buf[20];
2818 sprintf(buf,"%d",initialval);
2819 getnum_dlg[0].dp=(void *)prompt;
2820 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2821 getnum_dlg[2].dp=buf;
2822
2823 large_dialog(getnum_dlg);
2824
2825 int32_t ret = do_zqdialog(getnum_dlg,2);
2826
2827 if(ret==3)
2828 return atoi(buf);
2829
2830 return -1;
2831 }
2832
2833 int32_t gethexnumber(const char *prompt,int32_t initialval)
2834 {
2835 cancelgetnum=true;
2836 char buf[20];
2837 sprintf(buf,"%X",initialval);
2838 getnum_dlg[0].dp=(void *)prompt;
2839 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2840 getnum_dlg[2].dp=(void *)buf;
2841
2842 large_dialog(getnum_dlg);
2843
2844 int32_t ret=do_zqdialog(getnum_dlg,2);
2845
2846 if(ret!=0&&ret!=4)
2847 {
2848 cancelgetnum=false;
2849 }
2850
2851 if(ret==3)
2852 return zc_xtoi(buf);
2853
2854 return initialval;
2855 }
2856
2857 void update_combo_cycling()
2858 {
2859 Map.update_combo_cycling();
2860 }
2861
2862 void update_freeform_combos()
2863 {
2864 Map.update_freeform_combos();
2865 }
2866
2867 bool layers_valid(mapscr *tempscr)
2868 {
2869 for(int32_t i=0; i<6; i++)
2870 {
2871 if(tempscr->layermap[i]>map_count)
2872 {
2873 return false;
2874 }
2875 }
2876
2877 return true;
2878 }
2879
2880 void fix_layers(mapscr *tempscr, bool showwarning)
2881 {
2882 char buf[80]="layers have been changed: ";
2883
2884 for(int32_t i=0; i<6; i++)
2885 {
2886 if(tempscr->layermap[i]>map_count)
2887 {
2888 strcat(buf, "%d ");
2889 sprintf(buf, buf, i+1);
2890 tempscr->layermap[i]=0;
2891 }
2892 }
2893
2894 if(showwarning)
2895 {
2896 jwin_alert("Invalid layers detected",
2897 "One or more layers on this screen used",
2898 "maps that do not exist. The settings of these",
2899 buf, "O&K", NULL, 'o', 0, get_zc_font(font_lfont));
2900 }
2901 }
2902
2903 extern const char *colorlist(int32_t index, int32_t *list_size);
2904
2905 static char autobackup_str_buf[32];
2906 const char *autobackuplist(int32_t index, int32_t *list_size)
2907 {
2908 if(index>=0)
2909 {
2910 bound(index,0,10);
2911
2912 if(index==0)
2913 {
2914 sprintf(autobackup_str_buf,"Disabled");
2915 }
2916 else
2917 {
2918 sprintf(autobackup_str_buf,"%2d",index);
2919 }
2920
2921 return autobackup_str_buf;
2922 }
2923
2924 *list_size=11;
2925 return NULL;
2926 }
2927
2928 static char autosave_str_buf[32];
2929 const char *autosavelist(int32_t index, int32_t *list_size)
2930 {
2931 if(index>=0)
2932 {
2933 bound(index,0,10);
2934
2935 if(index==0)
2936 {
2937 sprintf(autosave_str_buf,"Disabled");
2938 }
2939 else
2940 {
2941 sprintf(autosave_str_buf,"%2d Minute%c",index,index>1?'s':0);
2942 }
2943
2944 return autosave_str_buf;
2945 }
2946
2947 *list_size=11;
2948 return NULL;
2949 }
2950
2951 const char *autosavelist2(int32_t index, int32_t *list_size)
2952 {
2953 if(index>=0)
2954 {
2955 bound(index,0,9);
2956 sprintf(autosave_str_buf,"%2d",index+1);
2957 return autosave_str_buf;
2958 }
2959
2960 *list_size=10;
2961 return NULL;
2962 }
2963
2964
2965 static int32_t options_1_list[] =
2966 {
2967 // dialog control number
2968 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1
2969 };
2970
2971 static int32_t options_2_list[] =
2972 {
2973 // dialog control number
2974 50, 51, -1
2975 };
2976
2977 static int32_t options_3_list[] =
2978 {
2979 // dialog control number
2980 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1
2981 };
2982 static int32_t options_4_list[] =
2983 {
2984 57, 58, 59, 60,
2985 -1
2986 };
2987
2988 static TABPANEL options_tabs[] =
2989 {
2990 // (text)
2991 { (char *)" 1 ", D_SELECTED, options_1_list, 0, NULL },
2992 { (char *)" 2 ", 0, options_2_list, 0, NULL },
2993 { (char *)" 3 ", 0, options_3_list, 0, NULL },
2994 { (char *)" 4 ", 0, options_4_list, 0, NULL },
2995 { NULL, 0, NULL, 0, NULL }
2996 };
2997
2998 12 static ListData autobackup_list(autobackuplist, &font);
2999 12 static ListData autosave_list(autosavelist, &font);
3000 12 static ListData autosave_list2(autosavelist2, &font);
3001 12 static ListData color_list(colorlist, &font);
3002 12 static ListData snapshotformat_list(snapshotformatlist, &font);
3003
3004 const char *dm_names[dm_max]=
3005 {
3006 "Normal",
3007 "Relational", // Removed.
3008 "Dungeon", // Removed.
3009 "Alias",
3010 "Pool",
3011 "Auto"
3012 };
3013
3014 void fix_drawing_mode_menu()
3015 {
3016 drawing_mode_menu.select_only_uid(draw_mode);
3017 }
3018
3019 int32_t onDrawingMode()
3020 {
3021 draw_mode=(draw_mode+1)%dm_max;
3022 int dm_relational = 1;
3023 if ((int)draw_mode == dm_relational)
3024 draw_mode += 2;
3025 fix_drawing_mode_menu();
3026 restore_mouse();
3027 return D_O_K;
3028 }
3029
3030 int32_t onDrawingModeNormal()
3031 {
3032 draw_mode=dm_normal;
3033 fix_drawing_mode_menu();
3034 restore_mouse();
3035 return D_O_K;
3036 }
3037
3038 int32_t onDrawingModeAlias()
3039 {
3040 if(draw_mode==dm_alias)
3041 {
3042 return onDrawingModeNormal();
3043 }
3044
3045 draw_mode=dm_alias;
3046 alias_cset_mod=0;
3047 fix_drawing_mode_menu();
3048 restore_mouse();
3049 return D_O_K;
3050 }
3051
3052 int32_t onDrawingModePool()
3053 {
3054 if(draw_mode==dm_cpool)
3055 {
3056 return onDrawingModeNormal();
3057 }
3058
3059 draw_mode=dm_cpool;
3060 fix_drawing_mode_menu();
3061 restore_mouse();
3062 return D_O_K;
3063 }
3064
3065 int32_t onDrawingModeAuto()
3066 {
3067 if (draw_mode == dm_auto)
3068 {
3069 return onDrawingModeNormal();
3070 }
3071
3072 draw_mode = dm_auto;
3073 fix_drawing_mode_menu();
3074 restore_mouse();
3075 return D_O_K;
3076 }
3077
3078 int32_t onReTemplate()
3079 {
3080 if(jwin_alert("Confirm Overwrite","Apply NES Dungeon template to","all screens on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
3081 {
3082 Map.TemplateAll();
3083 refresh(rALL);
3084 }
3085
3086 return D_O_K;
3087 }
3088
3089 int32_t onUndo()
3090 {
3091 Map.UndoCommand();
3092 refresh(rALL);
3093 return D_O_K;
3094 }
3095
3096 int32_t onRedo()
3097 {
3098 Map.RedoCommand();
3099 refresh(rALL);
3100 return D_O_K;
3101 }
3102
3103 int32_t onCopy()
3104 {
3105 if(prv_mode)
3106 {
3107 Map.set_prvcmb(Map.get_prvcmb()==0?1:0);
3108 return D_O_K;
3109 }
3110
3111 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3112 Map.Copy(screen);
3113 return D_O_K;
3114 }
3115
3116 int32_t onPaste()
3117 {
3118 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
3119 {
3120 if(CHECK_CTRL_CMD)
3121 return onPasteAllToAll();
3122 else return onPasteAll();
3123 }
3124 else if(CHECK_CTRL_CMD)
3125 return onPasteToAll();
3126 else
3127 {
3128 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3129 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartial, screen);
3130 }
3131 return D_O_K;
3132 }
3133
3134 int32_t onPasteAll()
3135 {
3136 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3137 Map.DoPasteScreenCommand(PasteCommandType::ScreenAll, screen);
3138 return D_O_K;
3139 }
3140
3141 int32_t onPasteToAll()
3142 {
3143 if(confirmBox("You are about to paste to all screens on the current map."))
3144 {
3145 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartialToEveryScreen);
3146 }
3147 return D_O_K;
3148 }
3149
3150 int32_t onPasteAllToAll()
3151 {
3152 if(confirmBox("You are about to paste to all screens on the current map."))
3153 {
3154 Map.DoPasteScreenCommand(PasteCommandType::ScreenAllToEveryScreen);
3155 }
3156 return D_O_K;
3157 }
3158
3159 int32_t onPasteUnderCombo()
3160 {
3161 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3162 Map.DoPasteScreenCommand(PasteCommandType::ScreenUnderCombo, screen);
3163 return D_O_K;
3164 }
3165
3166 int32_t onPasteSecretCombos()
3167 {
3168 Map.DoPasteScreenCommand(PasteCommandType::ScreenSecretCombos);
3169 return D_O_K;
3170 }
3171
3172 int32_t onPasteFFCombos()
3173 {
3174 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3175 Map.DoPasteScreenCommand(PasteCommandType::ScreenFFCombos, screen);
3176 return D_O_K;
3177 }
3178
3179 int32_t onPasteWarps()
3180 {
3181 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3182 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarps, screen);
3183 return D_O_K;
3184 }
3185
3186 int32_t onPasteScreenData()
3187 {
3188 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3189 Map.DoPasteScreenCommand(PasteCommandType::ScreenData, screen);
3190 return D_O_K;
3191 }
3192
3193 int32_t onPasteWarpLocations()
3194 {
3195 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3196 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarpLocations, screen);
3197 return D_O_K;
3198 }
3199
3200 int32_t onPasteDoors()
3201 {
3202 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3203 Map.DoPasteScreenCommand(PasteCommandType::ScreenDoors, screen);
3204 return D_O_K;
3205 }
3206
3207 int32_t onPasteLayers()
3208 {
3209 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3210 Map.DoPasteScreenCommand(PasteCommandType::ScreenLayers, screen);
3211 return D_O_K;
3212 }
3213
3214 int32_t onPastePalette()
3215 {
3216 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3217 Map.DoPasteScreenCommand(PasteCommandType::ScreenPalette, screen);
3218 return D_O_K;
3219 }
3220
3221 int32_t onPasteRoom()
3222 {
3223 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3224 Map.DoPasteScreenCommand(PasteCommandType::ScreenRoom, screen);
3225 return D_O_K;
3226 }
3227
3228 int32_t onPasteGuy()
3229 {
3230 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3231 Map.DoPasteScreenCommand(PasteCommandType::ScreenGuy, screen);
3232 return D_O_K;
3233 }
3234
3235 int32_t onPasteEnemies()
3236 {
3237 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3238 Map.DoPasteScreenCommand(PasteCommandType::ScreenEnemies, screen);
3239 return D_O_K;
3240 }
3241
3242 int32_t onDelete()
3243 {
3244 restore_mouse();
3245
3246 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3247 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
3248 if(!(scr->valid&mVALID) || jwin_alert("Confirm Delete","Delete this screen?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3249 {
3250 Map.DoClearScreenCommand(screen);
3251 }
3252
3253 saved=false;
3254 return D_O_K;
3255 }
3256
3257 int32_t onDeleteMap()
3258 {
3259 if(jwin_alert("Confirm Delete","Clear this entire map?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3260 {
3261 Map.clearmap(false);
3262 refresh(rALL);
3263 saved=false;
3264 }
3265
3266 return D_O_K;
3267 }
3268
3269 int32_t onToggleDarkness()
3270 {
3271 Map.CurrScr()->flags^=4;
3272 refresh(rMAP+rMENU);
3273 saved=false;
3274 return D_O_K;
3275 }
3276
3277 int32_t onIncMap()
3278 {
3279 int32_t m=Map.getCurrMap();
3280 int32_t oldcolor=Map.getcolor();
3281 Map.setCurrMap(m+1>=map_count?0:m+1);
3282 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3283 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3284
3285 int32_t newcolor=Map.getcolor();
3286
3287 if(newcolor!=oldcolor)
3288 {
3289 rebuild_trans_table();
3290 }
3291
3292 refresh(rALL);
3293 return D_O_K;
3294 }
3295
3296 int32_t onDecMap()
3297 {
3298 int32_t m=Map.getCurrMap();
3299 int32_t oldcolor=Map.getcolor();
3300 Map.setCurrMap((m-1<0)?map_count-1:zc_min(m-1,map_count-1));
3301 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3302 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3303
3304 int32_t newcolor=Map.getcolor();
3305
3306 if(newcolor!=oldcolor)
3307 {
3308 rebuild_trans_table();
3309 }
3310
3311 refresh(rALL);
3312 return D_O_K;
3313 }
3314
3315
3316 int32_t onDefault_Pals()
3317 {
3318 if(jwin_alert("Confirm Reset","Reset all palette data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3319 {
3320 saved=false;
3321
3322 if(!init_colordata(true, &header, &QMisc))
3323 {
3324 jwin_alert("Error","Palette reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3325 }
3326
3327 refresh_pal();
3328 }
3329
3330 return D_O_K;
3331 }
3332
3333 int32_t onDefault_Combos()
3334 {
3335 if(jwin_alert("Confirm Reset","Reset combo data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3336 {
3337 saved=false;
3338
3339 if(!init_combos(true, &header))
3340 {
3341 jwin_alert("Error","Combo reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3342 }
3343
3344 refresh(rALL);
3345 }
3346
3347 return D_O_K;
3348 }
3349
3350 int32_t onDefault_Items()
3351 {
3352 if(jwin_alert("Confirm Reset","Reset all items?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3353 {
3354 saved=false;
3355 reset_items(true, &header);
3356 }
3357
3358 return D_O_K;
3359 }
3360
3361 int32_t onDefault_Weapons()
3362 {
3363 if(jwin_alert("Confirm Reset","Reset weapon/misc. sprite data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3364 {
3365 saved=false;
3366 reset_wpns(true, &header);
3367 }
3368
3369 return D_O_K;
3370 }
3371
3372 int32_t onDefault_Guys()
3373 {
3374 if(jwin_alert("Confirm Reset","Reset all enemy/NPC data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3375 {
3376 saved=false;
3377 reset_guys();
3378 }
3379
3380 return D_O_K;
3381 }
3382
3383
3384 int32_t onDefault_Tiles()
3385 {
3386 if(jwin_alert("Confirm Reset","Reset all tiles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3387 {
3388 saved=false;
3389
3390 if(!init_tiles(true, &header))
3391 {
3392 jwin_alert("Error","Tile reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3393 }
3394
3395 refresh(rALL);
3396 }
3397
3398 return D_O_K;
3399 }
3400
3401 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2);
3402
3403 int32_t onDefault_SFX()
3404 {
3405 if(jwin_alert("Confirm Reset","Reset all sound effects?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3406 {
3407 saved=false;
3408 SAMPLE *temp_sample;
3409
3410 for(int32_t i=1; i<WAV_COUNT; i++)
3411 {
3412 temp_sample = (SAMPLE *)sfxdata[zc_min(i,Z35)].dat;
3413 change_sfx(&customsfxdata[i], temp_sample);
3414 sprintf(sfx_string[i],"s%03d",i);
3415
3416 if(i<Z35)
3417 strcpy(sfx_string[i], old_sfx_string[i-1]);
3418 set_bit(customsfxflag, i<Z35?1:0, i-1);
3419 }
3420 }
3421
3422 return D_O_K;
3423 }
3424
3425
3426 int32_t onDefault_MapStyles()
3427 {
3428 if(jwin_alert("Confirm Reset","Reset all map styles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3429 {
3430 saved=false;
3431 reset_mapstyles(true, &QMisc);
3432 }
3433
3434 return D_O_K;
3435 }
3436
3437 int onScrollScreen(int dir, bool warp)
3438 {
3439 Map.scroll(dir,warp);
3440 return D_O_K;
3441 }
3442
3443 int32_t onComboColLeft()
3444 {
3445 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3446 ;
3447 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3448 {
3449 First[current_combolist]-=1;
3450 clear_tooltip();
3451 refresh(rCOMBOS);
3452 }
3453 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3454 {
3455 combo_alistpos[current_comboalist]-=1;
3456 clear_tooltip();
3457 refresh(rCOMBOS);
3458 }
3459
3460 clear_keybuf();
3461 return D_O_K;
3462 }
3463
3464 int32_t onComboColRight()
3465 {
3466 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3467 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3468 ;
3469 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3470 {
3471 First[current_combolist]+=1;
3472 clear_tooltip();
3473 refresh(rCOMBOS);
3474 }
3475 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))&&(draw_mode==dm_alias))
3476 {
3477 combo_alistpos[current_comboalist]+=1;
3478 clear_tooltip();
3479 refresh(rCOMBOS);
3480 }
3481
3482 clear_keybuf();
3483 return D_O_K;
3484 }
3485
3486 int32_t onComboColUp()
3487 {
3488 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3489 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3490 ;
3491 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3492 {
3493 First[current_combolist]-=zc_min(First[current_combolist],sqr.w);
3494 clear_tooltip();
3495
3496 refresh(rCOMBOS);
3497 }
3498 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3499 {
3500 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],sqr.w);
3501 clear_tooltip();
3502 refresh(rCOMBOS);
3503 }
3504
3505 clear_keybuf();
3506 return D_O_K;
3507 }
3508
3509 int32_t onComboColDown()
3510 {
3511 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3512
3513 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3514 ;
3515 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3516 {
3517 First[current_combolist]+=zc_min((MAXCOMBOS-sqr.w)-First[current_combolist],sqr.w);
3518 clear_tooltip();
3519 refresh(rCOMBOS);
3520 }
3521 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(comboaliaslist[0].w*comboaliaslist[0].h)))&&(draw_mode==dm_alias))
3522 {
3523 combo_alistpos[current_comboalist]+=zc_min((MAXCOMBOALIASES-sqr.w)-combo_alistpos[current_comboalist],sqr.w);
3524 clear_tooltip();
3525 refresh(rCOMBOS);
3526 }
3527
3528 clear_keybuf();
3529 return D_O_K;
3530 }
3531
3532 void scrollup(int j)
3533 {
3534 switch(draw_mode)
3535 {
3536 case dm_alias:
3537 {
3538 auto& sqr = comboaliaslist[j];
3539 if(combo_alistpos[j]>0)
3540 {
3541 if(CHECK_CTRL_CMD)
3542 {
3543 combo_alistpos[j]=0;
3544 clear_tooltip();
3545 }
3546 else
3547 {
3548 combo_alistpos[j]-=zc_min(combo_alistpos[j],(sqr.w*sqr.h));
3549 clear_tooltip();
3550 }
3551
3552 refresh(rCOMBOS);
3553 }
3554 break;
3555 }
3556 case dm_cpool:
3557 {
3558 auto& sqr = comboaliaslist[j];
3559 if(combo_pool_listpos[j]>0)
3560 {
3561 if(CHECK_CTRL_CMD)
3562 {
3563 combo_pool_listpos[j]=0;
3564 clear_tooltip();
3565 }
3566 else
3567 {
3568 combo_pool_listpos[j]-=zc_min(combo_pool_listpos[j],(sqr.w*sqr.h));
3569 clear_tooltip();
3570 }
3571
3572 refresh(rCOMBOS);
3573 }
3574 break;
3575 }
3576 case dm_auto:
3577 {
3578 auto& sqr = comboaliaslist[j];
3579 if (combo_auto_listpos[j] > 0)
3580 {
3581 if (CHECK_CTRL_CMD)
3582 {
3583 combo_auto_listpos[j] = 0;
3584 clear_tooltip();
3585 }
3586 else
3587 {
3588 combo_auto_listpos[j] -= zc_min(combo_auto_listpos[j], (sqr.w * sqr.h));
3589 clear_tooltip();
3590 }
3591
3592 refresh(rCOMBOS);
3593 }
3594 break;
3595 }
3596 default:
3597 {
3598 auto& sqr = combolist[j];
3599 if(First[j]>0)
3600 {
3601 if(CHECK_CTRL_CMD)
3602 {
3603 First[j]-=zc_min(First[j],256);
3604 clear_tooltip();
3605 }
3606 else
3607 {
3608 First[j]-=zc_min(First[j],(sqr.w*sqr.h));
3609 clear_tooltip();
3610 }
3611
3612 refresh(rCOMBOS);
3613 }
3614 break;
3615 }
3616 }
3617 }
3618 void scrolldown(int j)
3619 {
3620 switch(draw_mode)
3621 {
3622 case dm_alias:
3623 {
3624 auto& sqr = comboaliaslist[j];
3625 if(combo_alistpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3626 {
3627 if(CHECK_CTRL_CMD)
3628 {
3629 combo_alistpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3630 clear_tooltip();
3631 }
3632 else
3633 {
3634 combo_alistpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_alistpos[j]+(sqr.w*sqr.h));
3635 clear_tooltip();
3636 }
3637
3638 refresh(rCOMBOS);
3639 }
3640 break;
3641 }
3642 case dm_cpool:
3643 {
3644 auto& sqr = comboaliaslist[j];
3645 if(combo_pool_listpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3646 {
3647 if(CHECK_CTRL_CMD)
3648 {
3649 combo_pool_listpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3650 clear_tooltip();
3651 }
3652 else
3653 {
3654 combo_pool_listpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_pool_listpos[j]+(sqr.w*sqr.h));
3655 clear_tooltip();
3656 }
3657
3658 refresh(rCOMBOS);
3659 }
3660 break;
3661 }
3662 case dm_auto:
3663 {
3664 auto& sqr = comboaliaslist[j];
3665 if (combo_auto_listpos[j] < (MAXCOMBOALIASES - (sqr.w * sqr.h)))
3666 {
3667 if (CHECK_CTRL_CMD)
3668 {
3669 combo_auto_listpos[j] = MAXCOMBOALIASES - (sqr.w * sqr.h);
3670 clear_tooltip();
3671 }
3672 else
3673 {
3674 combo_auto_listpos[j] = zc_min((MAXCOMBOALIASES - (sqr.w * sqr.h)), combo_pool_listpos[j] + (sqr.w * sqr.h));
3675 clear_tooltip();
3676 }
3677
3678 refresh(rCOMBOS);
3679 }
3680 break;
3681 }
3682 default:
3683 {
3684 auto& sqr = combolist[j];
3685 if(First[j]<(MAXCOMBOS-(sqr.w*sqr.h)))
3686 {
3687 if(CHECK_CTRL_CMD)
3688 {
3689 First[j]=zc_min((MAXCOMBOS-sqr.w*sqr.h),First[j]+256);
3690 clear_tooltip();
3691 }
3692 else
3693 {
3694 First[j]=zc_min((MAXCOMBOS-(sqr.w*sqr.h)),First[j]+(sqr.w*sqr.h));
3695 clear_tooltip();
3696 }
3697
3698 refresh(rCOMBOS);
3699 }
3700 break;
3701 }
3702 }
3703 }
3704
3705 int32_t onPgUp()
3706 {
3707 switch(draw_mode)
3708 {
3709 case dm_alias:
3710 scrollup(current_comboalist);
3711 break;
3712 case dm_cpool:
3713 scrollup(current_cpoollist);
3714 break;
3715 case dm_auto:
3716 scrollup(current_cautolist);
3717 break;
3718 default:
3719 scrollup(current_combolist);
3720 break;
3721 }
3722 return D_O_K;
3723 }
3724
3725 int32_t onPgDn()
3726 {
3727 switch(draw_mode)
3728 {
3729 case dm_alias:
3730 scrolldown(current_comboalist);
3731 break;
3732 case dm_cpool:
3733 scrolldown(current_cpoollist);
3734 break;
3735 case dm_auto:
3736 scrolldown(current_cautolist);
3737 break;
3738 default:
3739 scrolldown(current_combolist);
3740 break;
3741 }
3742 return D_O_K;
3743 }
3744
3745 int32_t onIncreaseCSet()
3746 {
3747 if(draw_mode!=dm_alias)
3748 {
3749 CSet=wrap(CSet+1,0,13);
3750 refresh(rCOMBOS+rMENU+rCOMBO);
3751 }
3752 else
3753 {
3754 alias_cset_mod=wrap(alias_cset_mod+1,0,13);
3755 }
3756 return D_O_K;
3757 }
3758
3759 int32_t onDecreaseCSet()
3760 {
3761 if(draw_mode!=dm_alias)
3762 {
3763 CSet=wrap(CSet-1,0,13);
3764 refresh(rCOMBOS+rMENU+rCOMBO);
3765 }
3766 else
3767 {
3768 alias_cset_mod=wrap(alias_cset_mod-1,0,13);
3769 }
3770 return D_O_K;
3771 }
3772
3773 int32_t onGotoPage()
3774 {
3775 if (draw_mode==dm_alias)
3776 {
3777 static const int PER_PAGE = 260;
3778 if(optional<int> v = call_get_num("Scroll to Alias Page", 0, MAXCOMBOALIASES/PER_PAGE-1, 0))
3779 combo_alistpos[current_comboalist] = *v*PER_PAGE;
3780 }
3781 else if (draw_mode==dm_cpool)
3782 {
3783 static const int PER_PAGE = 260;
3784 if(optional<int> v = call_get_num("Scroll to Combo Pool Page", 0, MAXCOMBOPOOLS/PER_PAGE-1, 0))
3785 combo_pool_listpos[current_cpoollist] = *v*PER_PAGE;
3786 }
3787 else if (draw_mode == dm_auto)
3788 {
3789 static const int PER_PAGE = 260;
3790 if(optional<int> v = call_get_num("Scroll to Auto Combo Page", 0, MAXAUTOCOMBOS/PER_PAGE-1, 0))
3791 combo_auto_listpos[current_cautolist] = *v*PER_PAGE;
3792 }
3793 else
3794 {
3795 static const int PER_PAGE = 256;
3796 if(optional<int> v = call_get_num("Scroll to Combo Page", 0, MAXCOMBOS/PER_PAGE-1, 0))
3797 First[current_combolist] = *v*PER_PAGE;
3798 }
3799
3800 return D_O_K;
3801 }
3802
3803 static char track_number_str_buf[MIDI_TRACK_BUFFER_SIZE] = {0};
3804 const char *tracknumlist(int32_t index, int32_t *list_size)
3805 {
3806 //memset(track_number_str_buf,0,50);
3807 if(index>=0)
3808 {
3809 bound(index,0,255);
3810 std::string name = zcmusic_get_track_name(zcmusic, index);
3811 sprintf(track_number_str_buf,"%02d %s",index+1, name.c_str());
3812 return track_number_str_buf;
3813 }
3814
3815 *list_size=zcmusic_get_tracks(zcmusic);
3816 return NULL;
3817 }
3818
3819 12 static ListData tracknum_list(tracknumlist, &font);
3820
3821 static DIALOG change_track_dlg[] =
3822 {
3823 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3824 12 { jwin_win_proc, 60-12, 40, 200-16, 72, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Track", NULL, NULL },
3825 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3826 12 { jwin_droplist_proc, 72-12, 60+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &tracknum_list, NULL, NULL },
3827 12 { jwin_button_proc, 70, 87, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
3828 12 { jwin_button_proc, 150, 87, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
3829 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
3830 };
3831 // return list_dlg[2].d1;
3832
3833 int32_t changeTrack()
3834 {
3835 restore_mouse();
3836 change_track_dlg[0].dp2=get_zc_font(font_lfont);
3837 change_track_dlg[2].d1=gme_track;
3838
3839 large_dialog(change_track_dlg);
3840
3841 if(do_zqdialog(change_track_dlg,2)==3)
3842 {
3843 gme_track=change_track_dlg[2].d1;
3844 zcmusic_change_track(zcmusic, gme_track);
3845 }
3846
3847 return D_O_K;
3848 }
3849
3850 void set_media_tunes()
3851 {
3852 media_menu.select_uid(MENUID_MEDIA_TUNES, true);
3853 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3854 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3855 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3856
3857 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3858 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3859 }
3860
3861 int32_t playMusic()
3862 {
3863 char *ext;
3864 bool ismidi=false;
3865 char allmusic_types[256];
3866 sprintf(allmusic_types, "%s;mid", zcmusic_types);
3867
3868 if(prompt_for_existing_file_compat("Load Music",(char*)allmusic_types,NULL,midipath,false))
3869 {
3870 strcpy(midipath,temppath);
3871
3872 ext=get_extension(midipath);
3873
3874 if(
3875 (stricmp(ext,"ogg")==0)||
3876 (stricmp(ext,"mp3")==0)||
3877 (stricmp(ext,"it")==0)||
3878 (stricmp(ext,"xm")==0)||
3879 (stricmp(ext,"s3m")==0)||
3880 (stricmp(ext,"mod")==0)||
3881 (stricmp(ext,"spc")==0)||
3882 (stricmp(ext,"gym")==0)||
3883 (stricmp(ext,"nsf")==0)||
3884 (stricmp(ext,"gbs")==0)||
3885 (stricmp(ext,"vgm")==0)
3886 )
3887 {
3888 ismidi=false;
3889 }
3890 else if((stricmp(ext,"mid")==0))
3891 {
3892 ismidi=true;
3893 }
3894 else
3895 {
3896 return D_O_K;
3897 }
3898
3899 zc_stop_midi();
3900
3901 if(zcmusic != NULL)
3902 {
3903 zcmusic_stop(zcmusic);
3904 zcmusic_unload_file(zcmusic);
3905 zcmusic = NULL;
3906 zcmixer->newtrack = NULL;
3907 }
3908
3909 if(ismidi)
3910 {
3911 packfile_password("");
3912 if((song=load_midi(midipath))!=NULL)
3913 {
3914 if(zc_play_midi(song,true)==0)
3915 {
3916 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3917 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3918 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3919 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3920
3921 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3922 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3923 }
3924 }
3925 }
3926 else
3927 {
3928 gme_track=0;
3929 zcmusic = (ZCMUSIC*)zcmusic_load_file(midipath);
3930
3931 if(zcmusic!=NULL)
3932 {
3933 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3934 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3935 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3936 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3937
3938 bool distrack = zcmusic_get_tracks(zcmusic)<2;
3939 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, distrack);
3940 disable_hotkey(ZQKEY_CHANGE_TRACK, distrack);
3941
3942 zcmusic_play(zcmusic, midi_volume);
3943 }
3944 }
3945 }
3946
3947 return D_O_K;
3948 }
3949
3950 int32_t playZCForever()
3951 {
3952 stopMusic();
3953
3954 zcmusic = zcmusic_load_file("assets/zc/ZC_Forever_HD.mp3");
3955 if (zcmusic)
3956 {
3957 zcmusic_play(zcmusic, midi_volume);
3958 set_media_tunes();
3959 }
3960 return D_O_K;
3961 }
3962
3963 // It took awhile to get these values right, so no meddlin'!
3964 int32_t playTune1()
3965 {
3966 return playTune(0);
3967 }
3968 int32_t playTune2()
3969 {
3970 return playTune(81);
3971 }
3972 int32_t playTune3()
3973 {
3974 return playTune(233);
3975 }
3976 int32_t playTune4()
3977 {
3978 return playTune(553);
3979 }
3980 int32_t playTune5()
3981 {
3982 return playTune(814);
3983 }
3984 int32_t playTune6()
3985 {
3986 return playTune(985);
3987 }
3988 int32_t playTune7()
3989 {
3990 return playTune(1153);
3991 }
3992 int32_t playTune8()
3993 {
3994 return playTune(1333);
3995 }
3996 int32_t playTune9()
3997 {
3998 return playTune(1556);
3999 }
4000 int32_t playTune10()
4001 {
4002 return playTune(1801);
4003 }
4004 int32_t playTune11()
4005 {
4006 return playTune(2069);
4007 }
4008 int32_t playTune12()
4009 {
4010 return playTune(2189);
4011 }
4012 int32_t playTune13()
4013 {
4014 return playTune(2569);
4015 }
4016 int32_t playTune14()
4017 {
4018 return playTune(2753);
4019 }
4020 int32_t playTune15()
4021 {
4022 return playTune(2856);
4023 }
4024 int32_t playTune16()
4025 {
4026 return playTune(3042);
4027 }
4028 int32_t playTune17()
4029 {
4030 return playTune(3125);
4031 }
4032 int32_t playTune18()
4033 {
4034 return playTune(3217);
4035 }
4036 int32_t playTune19()
4037 {
4038 return playTune(3296);
4039 }
4040
4041 int32_t playTune(int32_t pos)
4042 {
4043 zc_stop_midi();
4044
4045 if(zcmusic != NULL)
4046 {
4047 zcmusic_stop(zcmusic);
4048 zcmusic_unload_file(zcmusic);
4049 zcmusic = NULL;
4050 zcmixer->newtrack = NULL;
4051 }
4052
4053 if(zc_play_midi(asset_tunes_midi,true)==0)
4054 {
4055 zc_midi_seek(pos);
4056 set_media_tunes();
4057 }
4058
4059 return D_O_K;
4060 }
4061
4062 int32_t stopMusic()
4063 {
4064 zc_stop_midi();
4065
4066 if(zcmusic != NULL)
4067 {
4068 zcmusic_stop(zcmusic);
4069 zcmusic_unload_file(zcmusic);
4070 zcmusic = NULL;
4071 zcmixer->newtrack = NULL;
4072 }
4073
4074 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
4075 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
4076 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
4077 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
4078
4079 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
4080 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
4081 return D_O_K;
4082 }
4083
4084 static int32_t gamemisc1_list[] =
4085 {
4086 5,6,7,8,
4087 9,10,11,12,
4088
4089 37,38,39,40,
4090 41,42,43,44,
4091
4092 71,72,73,74,
4093 75,76,77,78,
4094
4095 -1
4096 };
4097
4098 static int32_t gamemisc2_list[] =
4099 {
4100 13,14,15,16,
4101 17,18,19,20,
4102
4103 45,46,47,48,
4104 49,50,51,52,
4105
4106 79,80,81,82,
4107 83,84,85,86,
4108
4109 -1
4110 };
4111
4112 static int32_t gamemisc3_list[] =
4113 {
4114 21,22,23,24,
4115 25,26,27,28,
4116
4117 53,54,55,56,
4118 57,58,59,60,
4119
4120 87,88,89,90,
4121 91,92,93,94,
4122
4123 -1
4124 };
4125
4126 static int32_t gamemisc4_list[] =
4127 {
4128 29,30,31,32,
4129 33,34,35,36,
4130
4131 61,62,63,64,
4132 65,66,67,68,
4133
4134 95,96,97,98,
4135 99,100,101,102,
4136
4137 -1
4138 };
4139
4140 static TABPANEL gamemisc_tabs[] =
4141 {
4142 // (text)
4143 { (char *)" Misc[0-7] ", D_SELECTED, gamemisc1_list, 0, NULL },
4144 { (char *)" Misc[8-15] ", 0, gamemisc2_list, 0, NULL },
4145 { (char *)" Misc[16-23] ", 0, gamemisc3_list, 0, NULL },
4146 { (char *)" Misc[24-31] ", 0, gamemisc4_list, 0, NULL },
4147 { NULL, 0, NULL, 0, NULL }
4148 };
4149
4150 //to do: Make string boxes larger, and split into two tabs.
4151 static DIALOG gamemiscarray_dlg[] =
4152 {
4153 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
4154
4155 { jwin_win_proc, 0, 10, 310, 224, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Game->Misc[]", NULL, NULL },
4156 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4157 { jwin_tab_proc, 3, 26, 304, 174, vc(14), vc(1), 0, 0, 1, 0, (void *) gamemisc_tabs, NULL, (void *)gamemiscarray_dlg },
4158 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4159 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4160
4161 //5
4162 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4163 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4164 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4165 //8
4166 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4167 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4168 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4169 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4170 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4171 //13
4172 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4173 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4174 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4175 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4176 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4177 //18
4178 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4179 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4180 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4181 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4182 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4183 //23
4184 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4185 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4186 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4187 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4188 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4189 //28
4190 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4191 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4192 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4193 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4194 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4195 //33
4196 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4197 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4198 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4199 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4200 //37
4201 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4202 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4203 //39
4204 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4205 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4206 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4207 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4208 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4209 //44
4210 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4211 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4212 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4213
4214 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4215 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4216 //49
4217 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4218 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4219 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4220 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4221 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4222 //54
4223 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4224 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4225 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4226 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4227 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4228 //59
4229 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4230 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4231 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4232 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4233 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4234 //64
4235 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4236 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4237 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4238 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4239 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4240 //69
4241 { jwin_button_proc, 70, 204, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4242 { jwin_button_proc, 170, 204, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4243
4244 //71
4245 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4246 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4247 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4248 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4249 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4250 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4251 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4252 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4253 //79
4254 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4255 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4256 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4257 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4258 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4259 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4260 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4261 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4262 //87
4263 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4264 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4265 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4266 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4267 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4268 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4269 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4270 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4271 //95
4272 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4273 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4274 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4275 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4276 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4277 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4278 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4279 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4280
4281 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4282 };
4283
4284 // +----------+
4285 // | |
4286 // | View Pic |
4287 // | |
4288 // | |
4289 // | |
4290 // +----------+
4291
4292 BITMAP *pic=NULL;
4293 BITMAP *bmap=NULL;
4294 PALETTE picpal;
4295 PALETTE mappal;
4296 int32_t picx=0,picy=0,mapx=0,mapy=0,pblack,pwhite;
4297
4298 double picscale=1.0,mapscale=1.0;
4299 bool vp_showpal=true, vp_showsize=true, vp_center=true;
4300
4301 //INLINE int32_t pal_sum(RGB p) { return p.r + p.g + p.b; }
4302
4303 void get_bw(RGB *pal,int32_t &black,int32_t &white)
4304 {
4305 black=white=1;
4306
4307 for(int32_t i=1; i<256; i++)
4308 {
4309 if(pal_sum(pal[i])<pal_sum(pal[black]))
4310 black=i;
4311
4312 if(pal_sum(pal[i])>pal_sum(pal[white]))
4313 white=i;
4314 }
4315 }
4316
4317 void draw_bw_mouse(int32_t white, int32_t old_mouse, int32_t new_mouse)
4318 {
4319 blit(mouse_bmp[old_mouse][0],mouse_bmp[new_mouse][0],0,0,0,0,16,16);
4320
4321 for(int32_t y=0; y<16; y++)
4322 {
4323 for(int32_t x=0; x<16; x++)
4324 {
4325 if(getpixel(mouse_bmp[new_mouse][0],x,y)!=0)
4326 {
4327 putpixel(mouse_bmp[new_mouse][0],x,y,white);
4328 }
4329 }
4330 }
4331 }
4332
4333 int32_t load_the_pic(BITMAP **dst, PALETTE dstpal)
4334 {
4335 PALETTE temppal;
4336
4337 for(int32_t i=0; i<256; i++)
4338 {
4339 temppal[i]=dstpal[i];
4340 dstpal[i]=RAMpal[i];
4341 }
4342
4343 // set up the new palette
4344 for(int32_t i=0; i<64; i++)
4345 {
4346 dstpal[i].r = i;
4347 dstpal[i].g = i;
4348 dstpal[i].b = i;
4349 }
4350
4351 zc_set_palette(dstpal);
4352
4353 BITMAP *graypic = create_bitmap_ex(8,screen->w,screen->h);
4354 int32_t _w = screen->w-1;
4355 int32_t _h = screen->h-1;
4356
4357 // gray scale the current frame
4358 for(int32_t y=0; y<_h; y++)
4359 {
4360 for(int32_t x=0; x<_w; x++)
4361 {
4362 int32_t c = screen->line[y][x];
4363 int32_t gray = zc_min((temppal[c].r*42 + temppal[c].g*75 + temppal[c].b*14) >> 7, 63);
4364 graypic->line[y][x] = gray;
4365 }
4366 }
4367
4368 blit(graypic,screen,0,0,0,0,screen->w,screen->h);
4369 destroy_bitmap(graypic);
4370 #ifdef __GNUC__
4371 #pragma GCC diagnostic ignored "-Wformat-overflow"
4372 #endif
4373 char extbuf[2][80];
4374 memset(extbuf[0],0,80);
4375 memset(extbuf[1],0,80);
4376 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4377 strcpy(extbuf[1], snapshotformat_str[0][1]);
4378
4379 for(int32_t i=1; i<ssfmtMAX; ++i)
4380 {
4381 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4382 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4383 }
4384
4385 sprintf(extbuf[0], "%s)", extbuf[0]);
4386 #ifdef __GNUC__
4387 #pragma GCC diagnostic pop
4388 #endif
4389
4390 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4391
4392 if(!gotit)
4393 {
4394 zc_set_palette(temppal);
4395 get_palette(dstpal);
4396 return 1;
4397 }
4398
4399 strcpy(imagepath,temppath);
4400
4401 if(*dst)
4402 {
4403 destroy_bitmap(*dst);
4404 }
4405
4406 for(int32_t i=0; i<256; i++)
4407 {
4408 dstpal[i].r = 0;
4409 dstpal[i].g = 0;
4410 dstpal[i].b = 0;
4411 }
4412
4413 *dst = load_bitmap(imagepath,picpal);
4414
4415 if(!*dst)
4416 {
4417 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4418 return 2;
4419 }
4420
4421 // get_bw(picpal,pblack,pwhite);
4422 // draw_bw_mouse(pwhite);
4423 // gui_bg_color = pblack;
4424 // gui_fg_color = pwhite;
4425
4426 if(vp_center)
4427 {
4428 picx=picy=0;
4429 }
4430 else
4431 {
4432 picx=(*dst)->w-zq_screen_w;
4433 picy=(*dst)->h-zq_screen_h;
4434 }
4435
4436 return 0;
4437 }
4438 int load_the_pic_new(BITMAP **dst, PALETTE dstpal)
4439 {
4440 #ifdef __GNUC__
4441 #pragma GCC diagnostic ignored "-Wformat-overflow"
4442 #endif
4443 char extbuf[2][80];
4444 memset(extbuf[0],0,80);
4445 memset(extbuf[1],0,80);
4446 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4447 strcpy(extbuf[1], snapshotformat_str[0][1]);
4448
4449 for(int32_t i=1; i<ssfmtMAX; ++i)
4450 {
4451 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4452 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4453 }
4454
4455 sprintf(extbuf[0], "%s)", extbuf[0]);
4456 #ifdef __GNUC__
4457 #pragma GCC diagnostic pop
4458 #endif
4459
4460 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4461
4462 if(!gotit)
4463 return 1;
4464
4465 strcpy(imagepath,temppath);
4466
4467 if(*dst)
4468 destroy_bitmap(*dst);
4469
4470 for(int32_t i=0; i<256; i++)
4471 {
4472 dstpal[i].r = 0;
4473 dstpal[i].g = 0;
4474 dstpal[i].b = 0;
4475 }
4476
4477 *dst = load_bitmap(imagepath,dstpal);
4478
4479 if(!*dst)
4480 {
4481 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4482 return 2;
4483 }
4484
4485 if(vp_center)
4486 {
4487 picx=picy=0;
4488 }
4489 else
4490 {
4491 picx=(*dst)->w-zq_screen_w;
4492 picy=(*dst)->h-zq_screen_h;
4493 }
4494
4495 return 0;
4496 }
4497
4498 int32_t saveMapAsImage(ALLEGRO_BITMAP* bitmap)
4499 {
4500 char buf[200];
4501 int32_t num=0;
4502
4503 do
4504 {
4505 snprintf(buf, 200, "%szquest_map%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
4506 buf[199]='\0';
4507 }
4508 while(num<99999 && exists(buf));
4509
4510 if (!al_save_bitmap(buf, bitmap))
4511 InfoDialog("Error", "Failed to save map image").show();
4512
4513 return D_O_K;
4514 }
4515
4516 int32_t onViewPic()
4517 {
4518 return launchPicViewer(&pic,picpal,&picx,&picy,&picscale,false);
4519 }
4520
4521
4522 class MapViewRTI : public RenderTreeItem
4523 {
4524 public:
4525
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
12 MapViewRTI(): RenderTreeItem("map_view")
4526 12 {
4527 12 }
4528
4529 int bw, bh, sw, sh, flags;
4530
4531 private:
4532 void render(bool bitmap_resized)
4533 {
4534 MapCursor previous_cursor = Map.getCursor();
4535 Map.setViewSize(1);
4536
4537 BITMAP* bmap4_single = create_bitmap_ex(8,256,176);
4538 set_bitmap_create_flags(true);
4539 ALLEGRO_BITMAP* bmap5_single = al_create_bitmap(256,176);
4540 for(int32_t y=0; y<8; y++)
4541 {
4542 for(int32_t x=0; x<16; x++)
4543 {
4544 clear_bitmap(bmap4_single);
4545 Map.setCurrScr(y*16+x);
4546 Map.draw(bmap4_single, 0, 0, flags, -1, y*16+x, -1);
4547 stretch_blit(bmap4_single, bmap4_single, 0, 0, 0, 0, 256, 176, 256, 176);
4548 all_render_a5_bitmap(bmap4_single, bmap5_single);
4549 al_draw_scaled_bitmap(bmap5_single, 0, 0, 256, 176, sw * x, sh * y, sw, sh, 0);
4550 }
4551 }
4552
4553 Map.setCursor(previous_cursor);
4554 destroy_bitmap(bmap4_single);
4555 al_destroy_bitmap(bmap5_single);
4556 }
4557 };
4558 12 static MapViewRTI rti_map_view;
4559
4560 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal, int32_t *px2, int32_t *py2, double *scale2, bool isviewingmap, bool skipmenu)
4561 {
4562 restore_mouse();
4563 BITMAP *buf;
4564 bool done=false, redraw=true;
4565
4566 popup_zqdialog_start();
4567
4568 // Always call load_the_map() when viewing the map.
4569 if((!*pictoview || isviewingmap) && (isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)))
4570 {
4571 zc_set_palette(RAMpal);
4572 popup_zqdialog_end();
4573 close_the_map();
4574 return D_O_K;
4575 }
4576
4577 get_bw(pal,pblack,pwhite);
4578
4579 int32_t oldfgcolor = gui_fg_color;
4580 int32_t oldbgcolor = gui_bg_color;
4581
4582 buf = create_bitmap_ex(8,zq_screen_w,zq_screen_h);
4583
4584 if(!buf)
4585 {
4586 jwin_alert("Error","Error creating temp bitmap",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4587 popup_zqdialog_end();
4588 close_the_map();
4589 return D_O_K;
4590 }
4591
4592 static LegacyBitmapRTI viewer_overlay_rti("viewer_overlay");
4593 viewer_overlay_rti.set_size(buf->w, buf->h);
4594 viewer_overlay_rti.a4_bitmap = buf;
4595 viewer_overlay_rti.transparency_index = 15;
4596 get_root_rti()->add_child(&viewer_overlay_rti);
4597
4598 zc_set_palette(pal);
4599
4600 if(isviewingmap)
4601 {
4602 set_center_root_rti(false);
4603
4604 int sw = rti_map_view.width / 16;
4605 int sh = rti_map_view.height / 8;
4606 int screen = Map.getCurrScr();
4607 if (screen >= 0x00 && screen <= 0x7F)
4608 {
4609 auto root_transform = get_root_rti()->get_transform();
4610 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4611 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4612 mapx = (-(screen % 16) * sw - sw/2 + dw/2);
4613 mapy = (-(screen / 16) * sh - sh/2 + dh/2);
4614 }
4615 }
4616
4617 do
4618 {
4619 int w, h;
4620 if (isviewingmap)
4621 {
4622 w = rti_map_view.width;
4623 h = rti_map_view.height;
4624 }
4625 else
4626 {
4627 w = (*pictoview)->w;
4628 h = (*pictoview)->h;
4629 }
4630
4631 if (isviewingmap)
4632 {
4633 float scale = *scale2;
4634 auto root_transform = get_root_rti()->get_transform();
4635 int dw = al_get_display_width(all_get_display()) / root_transform.xscale;
4636 int dh = al_get_display_height(all_get_display()) / root_transform.yscale;
4637 mapx = std::max(mapx, (int)(-w*scale + dw));
4638 mapy = std::max(mapy, (int)(-h*scale + dh));
4639 mapx = std::min(mapx, 0);
4640 mapy = std::min(mapy, 0);
4641 rti_map_view.set_transform({mapx, mapy, scale, scale});
4642 }
4643
4644 if(redraw)
4645 {
4646 clear_to_color(buf,15);
4647
4648 if (!isviewingmap)
4649 stretch_blit(*pictoview, buf, 0, 0, w, h,
4650 int32_t(zq_screen_w + (*px2 - w) * *scale2) / 2, int32_t(zq_screen_h + (*py2 - h) * *scale2) / 2,
4651 int32_t(w * *scale2), int32_t(h * *scale2));
4652
4653 if(vp_showpal)
4654 for(int32_t i=0; i<256; i++)
4655 rectfill(buf,((i&15)<<2)+zq_screen_w-64,((i>>4)<<2)+zq_screen_h-64,((i&15)<<2)+zq_screen_w-64+3,((i>>4)<<2)+zq_screen_h-64+3,i);
4656
4657 if(vp_showsize)
4658 {
4659 textprintf_ex(buf,font,0,zq_screen_h-8,pwhite,pblack,"%dx%d %.2f%%",w,h,*scale2*100.0);
4660 }
4661
4662 if (!isviewingmap)
4663 blit(buf,screen,0,0,0,0,zq_screen_w,zq_screen_h);
4664 redraw=false;
4665 }
4666
4667 custom_vsync();
4668
4669 int32_t step = 16;
4670
4671 if(*scale2 < 1.0)
4672 step = int32_t(4.0/ *scale2);
4673
4674 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
4675 step <<= 2;
4676
4677 if(CHECK_CTRL_CMD)
4678 step >>= 1;
4679
4680 if(key[KEY_UP])
4681 {
4682 *py2+=step;
4683 redraw=true;
4684 }
4685
4686 if(key[KEY_DOWN])
4687 {
4688 *py2-=step;
4689 redraw=true;
4690 }
4691
4692 if(key[KEY_LEFT])
4693 {
4694 *px2+=step;
4695 redraw=true;
4696 }
4697
4698 if(key[KEY_RIGHT])
4699 {
4700 *px2-=step;
4701 redraw=true;
4702 }
4703
4704 if(keypressed() && !redraw)
4705 switch(readkey()>>8)
4706 {
4707 case KEY_PGUP:
4708 *scale2*=0.95;
4709
4710 if(*scale2<0.1) *scale2=0.1;
4711
4712 redraw=true;
4713 break;
4714
4715 case KEY_PGDN:
4716 *scale2/=0.95;
4717
4718 if(*scale2>5.0) *scale2=5.0;
4719
4720 redraw=true;
4721 break;
4722
4723 case KEY_HOME:
4724 *scale2/=2.0;
4725
4726 if(*scale2<0.1) *scale2=0.1;
4727
4728 redraw=true;
4729 break;
4730
4731 case KEY_END:
4732 *scale2*=2.0;
4733
4734 if(*scale2>5.0) *scale2=5.0;
4735
4736 redraw=true;
4737 break;
4738
4739 case KEY_TILDE:
4740 *scale2=0.5;
4741 redraw=true;
4742 break;
4743
4744 case KEY_Z:
4745 *px2=w-zq_screen_w;
4746 *py2=h-zq_screen_h;
4747 vp_center=false;
4748 redraw=true;
4749 break;
4750
4751 case KEY_1:
4752 *scale2=1.0;
4753 redraw=true;
4754 break;
4755
4756 case KEY_2:
4757 *scale2=2.0;
4758 redraw=true;
4759 break;
4760
4761 case KEY_3:
4762 *scale2=3.0;
4763 redraw=true;
4764 break;
4765
4766 case KEY_4:
4767 *scale2=4.0;
4768 redraw=true;
4769 break;
4770
4771 case KEY_5:
4772 *scale2=5.0;
4773 redraw=true;
4774 break;
4775
4776 case KEY_C:
4777 *px2=*py2=0;
4778 redraw=vp_center=true;
4779 break;
4780
4781 case KEY_S:
4782 vp_showsize = !vp_showsize;
4783 redraw=true;
4784 break;
4785
4786 case KEY_D:
4787 vp_showpal = !vp_showpal;
4788 redraw=true;
4789 break;
4790
4791 case KEY_P:
4792 if(isviewingmap) break;
4793
4794 case KEY_ESC:
4795 done=true;
4796 break;
4797
4798 case KEY_SPACE:
4799 close_the_map();
4800 // TODO: why is `load_the_map` rendering a black dialog?
4801 if(isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)==2)
4802 {
4803 done=true;
4804 }
4805 else
4806 {
4807 redraw=true;
4808 gui_bg_color = pblack;
4809 gui_fg_color = pwhite;
4810 *scale2=1.0;
4811 zc_set_palette(pal);
4812 }
4813
4814 get_bw(pal,pblack,pwhite);
4815 break;
4816 }
4817 }
4818 while(!done);
4819
4820 destroy_bitmap(buf);
4821 zc_set_palette(RAMpal);
4822 gui_fg_color = oldfgcolor;
4823 gui_bg_color = oldbgcolor;
4824
4825 popup_zqdialog_end();
4826 position_mouse_z(0);
4827 viewer_overlay_rti.remove();
4828 set_center_root_rti(true);
4829 close_the_map();
4830 return D_O_K;
4831 }
4832
4833 static DIALOG loadmap_dlg[] =
4834 {
4835 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
4836 { jwin_win_proc, 0, 0, 225, 143, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Map", NULL, NULL },
4837 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4838 { jwin_text_proc, 32, 26, 96, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Resolution", NULL, NULL },
4839 // 3
4840 { jwin_radio_proc, 16, 36, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/4 - 1024x352", NULL, NULL },
4841 { jwin_radio_proc, 16, 46, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/2 - 2048x704", NULL, NULL },
4842 { jwin_radio_proc, 16, 56, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full - 4096x1408", NULL, NULL },
4843 { jwin_text_proc, 144, 26, 97, 9, vc(11), vc(1), 0, 0, 0, 0, (void *) "Options", NULL, NULL },
4844 // 7
4845 { jwin_check_proc, 144, 36, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Solidity", NULL, NULL },
4846 { jwin_check_proc, 144, 46, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Flags", NULL, NULL },
4847 { jwin_check_proc, 144, 56, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Dark", NULL, NULL },
4848 { jwin_check_proc, 144, 66, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Items", NULL, NULL },
4849 // 11
4850 { jwin_button_proc, 42, 110, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4851 { jwin_button_proc, 122, 110, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4852 { jwin_check_proc, 16, 88, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Save to Image", NULL, NULL },
4853 // 14
4854 { jwin_radio_proc, 16, 66, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"2x - 8192x2816", NULL, NULL },
4855 { jwin_radio_proc, 16, 76, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"4x - 16384x5632", NULL, NULL },
4856 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4857 };
4858
4859 int32_t load_the_map(bool skipmenu)
4860 {
4861 static int32_t res = 0;
4862 static int32_t flags = cDEBUG;
4863
4864 loadmap_dlg[0].dp2 = get_zc_font(font_lfont);
4865 loadmap_dlg[3].flags = (res==2) ? D_SELECTED : 0;
4866 loadmap_dlg[4].flags = (res==1) ? D_SELECTED : 0;
4867 loadmap_dlg[5].flags = (res==0) ? D_SELECTED : 0;
4868 loadmap_dlg[7].flags = (flags&cWALK) ? D_SELECTED : 0;
4869 loadmap_dlg[8].flags = (flags&cFLAGS) ? D_SELECTED : 0;
4870 loadmap_dlg[9].flags = (flags&cNODARK) ? 0 : D_SELECTED;
4871 loadmap_dlg[10].flags = (flags&cNOITEM) ? 0 : D_SELECTED;
4872 loadmap_dlg[13].flags = 0;
4873 loadmap_dlg[14].flags = (res==3) ? D_SELECTED : 0;
4874 loadmap_dlg[15].flags = (res==4) ? D_SELECTED : 0;
4875
4876 if(!skipmenu)
4877 {
4878 large_dialog(loadmap_dlg);
4879
4880 if (do_zqdialog(loadmap_dlg, 11) != 11)
4881 {
4882 return 1;
4883 }
4884
4885 flags = cDEBUG;
4886
4887 if(loadmap_dlg[3].flags&D_SELECTED) res=2;
4888
4889 if(loadmap_dlg[4].flags&D_SELECTED) res=1;
4890
4891 if(loadmap_dlg[5].flags&D_SELECTED) res=0;
4892
4893 if(loadmap_dlg[7].flags&D_SELECTED) flags|=cWALK;
4894
4895 if(loadmap_dlg[8].flags&D_SELECTED) flags|=cFLAGS;
4896
4897 if(!(loadmap_dlg[9].flags&D_SELECTED)) flags|=cNODARK;
4898
4899 if(!(loadmap_dlg[10].flags&D_SELECTED)) flags|=cNOITEM;
4900
4901 if(loadmap_dlg[14].flags&D_SELECTED) res=3;
4902
4903 if(loadmap_dlg[15].flags&D_SELECTED) res=4;
4904 }
4905
4906 int32_t bw = (256*16)>>res;
4907 int32_t bh = (176*8)>>res;
4908 int32_t sw = 256>>res;
4909 int32_t sh = 176>>res;
4910 if(res>2)
4911 {
4912 bw = (256*16)<<(res-2);
4913 bh = (176*8)<<(res-2);
4914 sw = 256<<(res-2);
4915 sh = 176<<(res-2);
4916 }
4917
4918 rti_map_view.flags = flags;
4919 rti_map_view.bw = bw;
4920 rti_map_view.bh = bh;
4921 rti_map_view.sw = sw;
4922 rti_map_view.sh = sh;
4923 rti_map_view.set_size(bw, bh);
4924 rti_map_view.dirty = true;
4925 get_root_rti()->add_child(&rti_map_view);
4926 render_zq();
4927
4928 vp_showpal = false;
4929 get_bw(picpal,pblack,pwhite);
4930 mapx = mapy = 0;
4931 mapscale = 1;
4932 imagepath[0] = 0;
4933
4934 if(loadmap_dlg[13].flags & D_SELECTED) saveMapAsImage(rti_map_view.bitmap);
4935
4936 memcpy(mappal,RAMpal,sizeof(RAMpal));
4937
4938 return 0;
4939 }
4940
4941 void close_the_map()
4942 {
4943 rti_map_view.remove();
4944 }
4945
4946 int32_t onViewMap()
4947 {
4948 return onViewMapEx(false);
4949 }
4950 int32_t onViewMapEx(bool skipmenu)
4951 {
4952 int32_t temp_aligns=ShowMisalignments;
4953 ShowMisalignments=0;
4954 //if(load_the_map()==0)
4955 //{
4956 launchPicViewer(&bmap,mappal,&mapx, &mapy, &mapscale,true,skipmenu);
4957 //}
4958 ShowMisalignments=temp_aligns;
4959 return D_O_K;
4960 }
4961
4962 static const char *mazedirstr[4] = {"North","South","West","East"};
4963 char _pathstr[40]="North,North,North,North";
4964
4965 char *pathstr(byte path[])
4966 {
4967 sprintf(_pathstr,"%s,%s,%s,%s",mazedirstr[path[0]],mazedirstr[path[1]],
4968 mazedirstr[path[2]],mazedirstr[path[3]]);
4969 return _pathstr;
4970 }
4971
4972 char _ticksstr[32]="99.99 seconds";
4973
4974 char *ticksstr(int32_t tics)
4975 {
4976 int32_t mins=tics/(60*60);
4977 tics=tics-(mins*60*60);
4978 int32_t secs=tics/60;
4979 tics=tics-(secs*60);
4980 tics=tics*100/60;
4981
4982 if(mins>0)
4983 {
4984 sprintf(_ticksstr,"%d:%02d.%02d",mins, secs, tics);
4985 }
4986 else
4987 {
4988 sprintf(_ticksstr,"%d.%02d seconds",secs, tics);
4989 }
4990
4991 return _ticksstr;
4992 }
4993 void textprintf_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4994 {
4995 char buf[512];
4996 va_list ap;
4997 ASSERT(bmp);
4998 ASSERT(f);
4999 ASSERT(format);
5000
5001 va_start(ap, format);
5002 uvszprintf(buf, sizeof(buf), format, ap);
5003 va_end(ap);
5004
5005
5006 textout_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5007
5008 textout_ex(bmp, f, buf, x, y, color_sh, -1);
5009 }
5010
5011 void textprintf_centre_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
5012 {
5013 char buf[512];
5014 va_list ap;
5015 ASSERT(bmp);
5016 ASSERT(f);
5017 ASSERT(format);
5018
5019 va_start(ap, format);
5020 uvszprintf(buf, sizeof(buf), format, ap);
5021 va_end(ap);
5022
5023 textout_centre_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5024 textout_centre_ex(bmp, f, buf, x, y, color_sh, -1);
5025 }
5026
5027 void draw_sqr_frame(size_and_pos const& sqr)
5028 {
5029 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.tw(),sqr.th(),FR_DEEP);
5030 }
5031 void draw_sqr_icon(size_and_pos const& sqr, BITMAP* icon)
5032 {
5033 stretch_blit(icon, menu1, 0, 0, 16, 16, sqr.x+2, sqr.y+2, sqr.tw()-4, sqr.th()-4);
5034 }
5035 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num)
5036 {
5037 if(center)
5038 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5039 else
5040 textprintf_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5041 }
5042 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num1, int num2)
5043 {
5044 if(center)
5045 {
5046 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5047 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5048 }
5049 else
5050 {
5051 textprintf_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5052 textprintf_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5053 }
5054 }
5055 void draw_sqr_btn(size_and_pos const& sqr, const char* txt, int flags, FONT* f = nullptr)
5056 {
5057 if(sqr.x < 0) return;
5058 FONT* tfont = font;
5059 if(f)
5060 font = f;
5061 draw_text_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), txt, 0, 0, flags, true);
5062 font = tfont;
5063 }
5064 void draw_sqr_btn(size_and_pos const& sqr, int icon, int flags, FONT* f = nullptr)
5065 {
5066 if(sqr.x < 0) return;
5067 FONT* tfont = font;
5068 if(f)
5069 font = f;
5070 draw_icon_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), icon, 0, 0, flags, true);
5071 font = tfont;
5072 }
5073
5074 void drawpanel()
5075 {
5076 mapscr *scr=Map.CurrScr();
5077 int32_t NextCombo = combobuf[Combo].nextcombo;
5078 int32_t NextCSet = combobuf[Combo].nextcset;
5079 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
5080 {
5081 NextCombo = scr->undercombo;
5082 NextCSet = scr->undercset;
5083 }
5084 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
5085 NextCSet = CSet;
5086
5087 FONT* tfont = font;
5088 if(prv_mode)
5089 {
5090 jwin_draw_frame(menu1,0,preview_panel.y,preview_panel.x+preview_panel.w, preview_panel.h, FR_WIN);
5091 rectfill(menu1,preview_panel.x,preview_panel.y+2,preview_panel.x+preview_panel.w-3,preview_panel.y+preview_panel.h-3,jwin_pal[jcBOX]);
5092 }
5093 else
5094 {
5095 auto& sqr = main_panel;
5096 rectfill(menu1,sqr.x,sqr.y,sqr.x+sqr.w-1,sqr.y+sqr.h-1, jwin_pal[jcBOX]);
5097 refresh(rSCRMAP);
5098 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.w,sqr.h, FR_WIN);
5099
5100 font = get_custom_font(CFONT_GUI);
5101 draw_sqr_btn(squarepanel_swap_btn, "SWP", 0);
5102 if(compact_square_panels)
5103 {
5104 textprintf_centre_ex(menu1,font,squarepanel_up_btn.cx(),squarepanel_up_btn.y-text_height(font)-2,jwin_pal[jcBOXFG],-1,"%d",compact_active_panel);
5105 draw_sqr_btn(squarepanel_up_btn, BTNICON_ARROW_UP, 0);
5106 draw_sqr_btn(squarepanel_down_btn, BTNICON_ARROW_DOWN, 0);
5107 }
5108 font = tfont;
5109
5110 FONT* sqr_text_font = (is_compact && compact_square_panels) ? get_custom_font(CFONT_GUI) : font;
5111 //Item:
5112 if(itemsqr_pos.x > -1)
5113 {
5114 draw_sqr_frame(itemsqr_pos);
5115 if(scr->hasitem)
5116 {
5117 rectfill(menu1,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsqr_pos.x+itemsqr_pos.tw()-3,itemsqr_pos.y+itemsqr_pos.th()-3,0);
5118 overtile16_scale(menu1, itemsbuf[scr->item].tile,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsbuf[scr->item].csets&15,0,itemsqr_pos.tw()-4,itemsqr_pos.th()-4);
5119 }
5120 else draw_sqr_icon(itemsqr_pos, icon_bmp[0][coord_frame]);
5121 draw_sqr_nums(itemsqr_pos, sqr_text_font, panel_align == 1, scr->itemx, scr->itemy);
5122 }
5123 //Flag:
5124 if(flagsqr_pos.x > -1)
5125 {
5126 draw_sqr_frame(flagsqr_pos);
5127 draw_sqr_icon(flagsqr_pos,flag_bmp[Flag%16][coord_frame]);
5128 draw_sqr_nums(flagsqr_pos, sqr_text_font, panel_align == 1, Flag);
5129 }
5130
5131 //Stairs:
5132 if(stairsqr_pos.x > -1)
5133 {
5134 draw_sqr_frame(stairsqr_pos);
5135 draw_sqr_icon(stairsqr_pos,icon_bmp[1][coord_frame]);
5136 draw_sqr_nums(stairsqr_pos, sqr_text_font, panel_align == 1, scr->stairx, scr->stairy);
5137 }
5138
5139 //Green arrival square:
5140 bool disabled_arrival = get_qr(qr_NOARRIVALPOINT);
5141 if(warparrival_pos.x > -1)
5142 {
5143 draw_sqr_frame(warparrival_pos);
5144 BITMAP* icon = icon_bmp[2][coord_frame];
5145 if(disabled_arrival)
5146 {
5147 icon = create_bitmap_ex(8,16,16);
5148 blit(icon_bmp[2][0], icon, 0, 0, 0, 0, 16, 16);
5149 replColor(icon, 0xE7, 0xEA, 0xEA, false);
5150 replColor(icon, 0xE8, 0xE2, 0xE2, false);
5151 }
5152
5153 draw_sqr_icon(warparrival_pos, icon);
5154 draw_sqr_nums(warparrival_pos, sqr_text_font, panel_align == 1, scr->warparrivalx, scr->warparrivaly);
5155
5156 if(disabled_arrival)
5157 destroy_bitmap(icon);
5158 }
5159
5160 //Blue return squares:
5161 for(int32_t i=0; i<4; i++)
5162 {
5163 if(warpret_pos[i].x < 0) continue;
5164 draw_sqr_frame(warpret_pos[i]);
5165 draw_sqr_icon(warpret_pos[i], icon_bmp[ICON_BMP_RETURN_A+i][coord_frame]);
5166 draw_sqr_nums(warpret_pos[i], sqr_text_font, panel_align == 1, scr->warpreturnx[i], scr->warpreturny[i]);
5167 }
5168
5169 // Enemies
5170 auto& ep = enemy_prev_pos;
5171 if(ep.x > -1)
5172 {
5173 if(ep.fw > -1)
5174 {
5175 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5176 rectfill(menu1, ep.x+ep.fw, ep.y+ep.fh, ep.x+ep.tw()-1, ep.y+ep.th()-1, jwin_pal[jcBOX]);
5177 jwin_draw_frag_frame(menu1, ep.x, ep.y, ep.tw(), ep.th(), ep.fw, ep.fh, FR_DEEP);
5178 }
5179 else
5180 {
5181 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5182 draw_sqr_frame(ep);
5183 }
5184 for(int32_t i=0; i< 10 && Map.CurrScr()->enemy[i]!=0; i++)
5185 {
5186 int32_t id = Map.CurrScr()->enemy[i];
5187 int32_t tile = get_qr(qr_NEWENEMYTILES) ? guysbuf[id].e_tile : guysbuf[id].tile;
5188 int32_t cset = guysbuf[id].cset;
5189 auto& sqr = ep.subsquare(i);
5190 if(tile)
5191 overtile16_scale(menu1, tile+efrontfacingtile(id),sqr.x,sqr.y,cset,0,sqr.tw(),sqr.th());
5192 }
5193 }
5194 }
5195 font = tfont;
5196 }
5197
5198 void show_screen_error(const char *str, int32_t i, int32_t c)
5199 {
5200 rectfill(menu1, screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),screrrorpos.x,screrrorpos.y-((i-1)*16)-4,vc(0));
5201 textout_shadowed_ex(menu1,get_zc_font(font_lfont_l), str,screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),c,vc(0),-1);
5202 }
5203
5204 void tile_warp_notification(int32_t which, char *buf)
5205 {
5206 char letter = 'A'+which;
5207
5208 switch(Map.CurrScr()->tilewarptype[which])
5209 {
5210 case wtCAVE:
5211 sprintf(buf,"Tile Warp %c: Cave/Item Cellar",letter);
5212 break;
5213
5214 default:
5215 {
5216 char buf2[30];
5217
5218 if(strlen(DMaps[Map.CurrScr()->tilewarpdmap[which]].name)==0)
5219 {
5220 sprintf(buf2,"%d",Map.CurrScr()->tilewarpdmap[which]);
5221 }
5222 else
5223 sprintf(buf2,"%d-%s",Map.CurrScr()->tilewarpdmap[which],DMaps[Map.CurrScr()->tilewarpdmap[which]].name);
5224
5225 sprintf(buf,"Tile Warp %c: %s, %02X", letter, buf2, Map.CurrScr()->tilewarpscr[which]);
5226 break;
5227 }
5228
5229 case wtNOWARP:
5230 sprintf(buf,"Tile Warp %c: Cancel Warp", letter);
5231 break;
5232 }
5233 }
5234
5235 void side_warp_notification(int32_t which, int32_t dir, char *buf)
5236 {
5237 char letter = 'A'+which;
5238 char buf3[16];
5239
5240 if(dir==0 && Map.CurrScr()->timedwarptics)
5241 sprintf(buf3,"%s, Timed",mazedirstr[dir]);
5242 else if(dir==4)
5243 sprintf(buf3,"Timed");
5244 else
5245 strcpy(buf3, mazedirstr[dir]);
5246
5247 switch(Map.CurrScr()->sidewarptype[which])
5248 {
5249 case wtCAVE:
5250 sprintf(buf,"Side Warp %c (%s): Cave/Item Cellar",letter, buf3);
5251 break;
5252
5253 default:
5254 {
5255 // Destination DMap name
5256 if(strlen(DMaps[Map.CurrScr()->sidewarpdmap[which]].name)==0)
5257 {
5258 sprintf(buf,"Side Warp %c (%s): %d, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which], Map.CurrScr()->sidewarpscr[which]);
5259 }
5260 else
5261 sprintf(buf,"Side Warp %c (%s): %d-%s, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which],DMaps[Map.CurrScr()->sidewarpdmap[which]].name, Map.CurrScr()->sidewarpscr[which]);
5262
5263 break;
5264 }
5265
5266 case wtNOWARP:
5267 sprintf(buf,"Side Warp %c (%s): Cancel Warp", letter, buf3);
5268 break;
5269 }
5270 }
5271
5272 static bool arrowcursor = true; // Used by combo aliases and Combo Brush cursors. -L
5273
5274 void xout(BITMAP* dest, int x, int y, int x2, int y2, int c, int bgc = -1)
5275 {
5276 //BG Fill
5277 if(bgc > -1)
5278 rectfill(dest, x, y, x2, y2, bgc);
5279 ++x; ++y; --x2; --y2;
5280 //Border
5281 safe_rect(dest, x, y, x2, y2, c);
5282 //line(dest, x, y, x2, y, c);
5283 //line(dest, x, y, x, y2, c);
5284 //X
5285 line(dest, x, y, x2, y2, c);
5286 line(dest, x, y2, x2, y, c);
5287 }
5288
5289 void put_autocombo_engravings(BITMAP* dest, combo_auto const& ca, bool selected, int32_t x, int32_t y, int32_t scale)
5290 {
5291 if (!ca.valid())
5292 {
5293 if (ca.getDisplay() > 0)
5294 put_engraving(dest, x, y, 15, scale);
5295 }
5296 else
5297 {
5298 if (ca.getType() == AUTOCOMBO_Z4 || ca.getType() == AUTOCOMBO_DOR)
5299 {
5300 byte hei = vbound(ca.getArg() + 1, 1, 9);
5301 if (selected)
5302 hei = vbound(cauto_height, 1, 9);
5303 put_engraving(dest, x, y, 15 - hei, scale);
5304 }
5305 }
5306 }
5307
5308 void draw_screenunit_map_screen(VisibleScreen visible_screen)
5309 {
5310 int num_screens_to_draw = Map.getViewSize();
5311 int screen = visible_screen.screen;
5312 int xoff = visible_screen.xoff;
5313 int yoff = visible_screen.yoff;
5314
5315 mapscr* scr = visible_screen.scr;
5316 if (!layers_valid(scr))
5317 fix_layers(scr, true);
5318
5319 clear_to_color(mapscreenbmp, jwin_pal[jcBOX]);
5320 if (LayerDitherBG > -1)
5321 {
5322 if (LayerDitherSz > 0)
5323 ditherblit(mapscreenbmp, nullptr, vc(LayerDitherBG), dithChecker, LayerDitherSz);
5324 else
5325 clear_to_color(mapscreenbmp, vc(LayerDitherBG));
5326 }
5327
5328 int view_scr_x = Map.getViewScr() % 16;
5329 int view_scr_y = Map.getViewScr() / 16;
5330 int scr_x = screen % 16;
5331 int scr_y = screen / 16;
5332 int edge_xoff = 0, edge_yoff = 0;
5333 if(showedges)
5334 {
5335 if (scr_x == view_scr_x)
5336 edge_xoff = 16;
5337 else
5338 xoff -= 16;
5339
5340 if (scr_y == view_scr_y)
5341 edge_yoff = 16;
5342 else
5343 yoff -= 16;
5344 }
5345
5346 combotile_add_x = mapscreen_x + xoff;
5347 combotile_add_y = mapscreen_y + yoff;
5348 combotile_mul_x = mapscreen_single_scale;
5349 combotile_mul_y = mapscreen_single_scale;
5350 Map.draw(mapscreenbmp, scr_x == view_scr_x && showedges ? 16 : 0, scr_y == view_scr_y && showedges ? 16 : 0, Flags, Map.getCurrMap(), screen, ActiveLayerHighlight ? CurrentLayer : -1);
5351 combotile_add_x = 0;
5352 combotile_add_y = 0;
5353 combotile_mul_x = 1;
5354 combotile_mul_y = 1;
5355
5356 // TODO: should be better to move this out of draw_screenunit_map_screen.
5357 if (showedges && screen < 128)
5358 {
5359 bool peek_above = scr_y == view_scr_y;
5360 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5361 bool peek_left = scr_x == view_scr_x;
5362 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5363
5364 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5365 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5366
5367 //not the first row of screens
5368 if (peek_above)
5369 {
5370 if(screen>15 && !NoScreenPreview)
5371 {
5372 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5373 }
5374 else
5375 {
5376 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5377 }
5378 }
5379
5380 //not the last row of screens
5381 if (peek_below)
5382 {
5383 if(screen + 16 < 0x80 && !NoScreenPreview)
5384 {
5385 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5386 }
5387 else
5388 {
5389 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5390 }
5391 }
5392
5393 //not the first column of screens
5394 if (peek_left)
5395 {
5396 if(screen&0x0F && !NoScreenPreview)
5397 {
5398 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5399 }
5400 else
5401 {
5402 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5403 }
5404 }
5405
5406 //not the last column of screens
5407 if (peek_right)
5408 {
5409 if((screen&0x0F)<15 && !NoScreenPreview)
5410 {
5411 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5412 }
5413 else
5414 {
5415 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5416 }
5417 }
5418
5419 //not the first row or first column of screens
5420 if (peek_above && peek_left)
5421 {
5422 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5423 {
5424 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5425 }
5426 else
5427 {
5428 Map.drawstaticblock(mapscreenbmp, 0, 0);
5429 }
5430 }
5431
5432 //not the first row or last column of screens
5433 if (peek_above && peek_right)
5434 {
5435 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5436 {
5437 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5438 }
5439 else
5440 {
5441 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5442 }
5443 }
5444
5445 //not the last row or first column of screens
5446 if (peek_below && peek_left)
5447 {
5448 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5449 {
5450 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5451 }
5452 else
5453 {
5454 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5455 }
5456 }
5457
5458 //not the last row or last column of screens
5459 if (peek_below && peek_right)
5460 {
5461 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5462 {
5463 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5464 }
5465 else
5466 {
5467 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5468 }
5469 }
5470 }
5471
5472 if (ShowSquares && Map.getViewSize() < 4)
5473 {
5474 if(scr->stairx || scr->stairy)
5475 {
5476 int32_t x1 = scr->stairx+edge_xoff;
5477 int32_t y1 = scr->stairy+edge_yoff;
5478 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5479 }
5480
5481 if(scr->warparrivalx || scr->warparrivaly)
5482 {
5483 int32_t x1 = scr->warparrivalx +edge_xoff;
5484 int32_t y1 = scr->warparrivaly +edge_yoff;
5485 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5486 }
5487
5488 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5489 {
5490 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5491 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5492 int32_t clr = vc(9);
5493
5494 if(FlashWarpSquare==i)
5495 {
5496 if(!FlashWarpClk)
5497 FlashWarpSquare=-1;
5498 else if(!(--FlashWarpClk%3))
5499 clr = vc(15);
5500 }
5501
5502 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5503 }
5504 }
5505
5506 if(ShowFFCs)
5507 {
5508 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5509 int num_ffcs = ffscr->numFFC();
5510 for(int32_t i=num_ffcs-1; i>=0; i--)
5511 {
5512 ffcdata& ff = ffscr->ffcs[i];
5513 if(ff.data !=0 && (CurrentLayer<2 || (ff.flags&ffc_overlay)))
5514 {
5515 auto x = ff.x+edge_xoff;
5516 auto y = ff.y+edge_yoff;
5517 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5518 }
5519 }
5520 }
5521
5522 if(!(Flags&cDEBUG) && pixeldb==1)
5523 {
5524 for(int32_t j=168; j<176; j++)
5525 {
5526 for(int32_t i=0; i<256; i++)
5527 {
5528 if(((i^j)&1)==0)
5529 {
5530 putpixel(mapscreenbmp,edge_xoff+i,
5531 edge_yoff+j,vc(blackout_color));
5532 }
5533 }
5534 }
5535 }
5536
5537 int w = mapscreenbmp->w * mapscreen_single_scale;
5538 int h = mapscreenbmp->h * mapscreen_single_scale;
5539 stretch_blit(mapscreenbmp, menu1, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5540 }
5541
5542 void draw_screenunit(int32_t unit, int32_t flags)
5543 {
5544 FONT* tfont = font;
5545 switch(unit)
5546 {
5547 case rSCRMAP:
5548 {
5549 size_and_pos *mini_sqr = &minimap;
5550 size_and_pos *real_mini_sqr = &real_minimap;
5551
5552 if(zoomed_minimap)
5553 {
5554 mini_sqr = &minimap_zoomed;
5555 real_mini_sqr = &real_minimap_zoomed;
5556 }
5557
5558 auto txt_x = real_mini_sqr->x+2+8*real_mini_sqr->xscale;
5559 auto txt_y = real_mini_sqr->y+2+8*real_mini_sqr->yscale;
5560
5561 rectfill(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->x+mini_sqr->w-1,mini_sqr->y+mini_sqr->h-1,jwin_pal[jcBOX]);
5562 if(zoomed_minimap)
5563 jwin_draw_frame(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->w,mini_sqr->h,FR_WIN);
5564 jwin_draw_minimap_frame(menu1,real_mini_sqr->x,real_mini_sqr->y,real_mini_sqr->tw(), real_mini_sqr->th(), real_mini_sqr->xscale, FR_DEEP);
5565
5566 if(Map.getCurrMap()<Map.getMapCount())
5567 {
5568 for(int32_t i=0; i<MAPSCRS; i++)
5569 {
5570 auto& sqr = real_mini_sqr->subsquare(i);
5571
5572 if(Map.Scr(i)->valid&mVALID)
5573 {
5574 // Handled by mmap_draw.
5575 }
5576 else
5577 {
5578 if (InvalidBG == 2)
5579 {
5580 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
5581 }
5582 else if (InvalidBG == 1)
5583 {
5584 for(int32_t dy=0; dy<sqr.h; dy++)
5585 {
5586 for(int32_t dx=0; dx<sqr.w; dx++)
5587 {
5588 menu1->line[dy+sqr.y][dx+sqr.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
5589 }
5590 }
5591 }
5592 else
5593 {
5594 int32_t offs = 2*(sqr.w/9);
5595 draw_x(menu1, sqr.x+offs, sqr.y+offs, sqr.x+sqr.w-1-offs, sqr.y+sqr.h-1-offs, vc(15));
5596 }
5597 }
5598 }
5599
5600 int32_t s=Map.getCurrScr();
5601
5602 BITMAP* txtbmp = create_bitmap_ex(8,256,64);
5603 clear_bitmap(txtbmp);
5604 int txtscale = zoomed_minimap ? (is_compact ? 2 : 3) : 1;
5605 font = get_zc_font(font_lfont_l);
5606
5607 int32_t space = text_length(font, "255")+2, spc_s = text_length(font, "S")+2, spc_m = text_length(font, "M")+2;
5608 textprintf_disabled(txtbmp,font,0,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"M");
5609 static int map_shortcut_tooltip_id = ttip_register_id();
5610 ttip_install(map_shortcut_tooltip_id, "Prev map: ,\nNext map: .", txt_x, txt_y, 30, 20, txt_x, txt_y - 60);
5611
5612 textprintf_ex(txtbmp,font,spc_m,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%-3d",Map.getCurrMap()+1);
5613
5614 textprintf_disabled(txtbmp,font,spc_m+space,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"S");
5615 textprintf_ex(txtbmp,font,spc_m+space+spc_s,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"0x%02X (%d)",s, s);
5616 masked_stretch_blit(txtbmp, menu1, 0, 0, 256, 64, txt_x, txt_y, 256*txtscale, 64*txtscale);
5617 destroy_bitmap(txtbmp);
5618 }
5619 }
5620 break;
5621 case rMAP:
5622 {
5623 refresh_visible_screens();
5624 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
5625
5626 int num_combos_width = 16 * Map.getViewSize();
5627 int num_combos_height = 11 * Map.getViewSize();
5628
5629 if(CurrentLayer > 0 && !mapscreen_valid_layers[CurrentLayer-1])
5630 CurrentLayer = 0;
5631
5632 for (auto& vis_screen : visible_screens)
5633 {
5634 draw_screenunit_map_screen(vis_screen);
5635 }
5636
5637 if (showxypos_icon)
5638 {
5639 int x0 = showxypos_x + (showedges?16:0);
5640 int y0 = showxypos_y + (showedges?16:0);
5641 int x1 = x0 + showxypos_w - 1;
5642 int y1 = y0 + showxypos_h - 1;
5643 x0 *= mapscreen_single_scale;
5644 y0 *= mapscreen_single_scale;
5645 x1 *= mapscreen_single_scale;
5646 y1 *= mapscreen_single_scale;
5647 x0 += mapscreen_x;
5648 y0 += mapscreen_y;
5649 x1 += mapscreen_x;
5650 y1 += mapscreen_y;
5651
5652 if (showxypos_color == vc(15))
5653 safe_rect(menu1, x0, y0, x1, y1, showxypos_color);
5654 else
5655 rectfill(menu1, x0, y0, x1, y1, showxypos_color);
5656 }
5657
5658 if(showxypos_cursor_icon)
5659 {
5660 int x0 = showxypos_cursor_x + (showedges?16:0);
5661 int y0 = showxypos_cursor_y + (showedges?16:0);
5662 int x1 = x0 + showxypos_w - 1;
5663 int y1 = y0 + showxypos_h - 1;
5664 x0 *= mapscreen_single_scale;
5665 y0 *= mapscreen_single_scale;
5666 x1 *= mapscreen_single_scale;
5667 y1 *= mapscreen_single_scale;
5668 x0 += mapscreen_x;
5669 y0 += mapscreen_y;
5670 x1 += mapscreen_x;
5671 y1 += mapscreen_y;
5672 safe_rect(menu1, x0, y0, x1, y1, showxypos_cursor_color);
5673 }
5674
5675 // Draw dithering over the edge/preview combos.
5676 if(showedges)
5677 {
5678 int tile_size = 16 * mapscreen_single_scale;
5679 int tiles_across = (16 * Map.getViewSize()) + 2;
5680 int bottom_row_y = (Map.getViewSize()*11 + 1) * tile_size;
5681 int right_col_x = (Map.getViewSize()*16 + 1) * tile_size;
5682
5683 //top preview
5684 for(int32_t j=0; j<tile_size; j++)
5685 {
5686 for(int32_t i=0; i<tiles_across * tile_size; i++)
5687 {
5688 if(((i^j)&1)==0)
5689 {
5690 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5691 }
5692 }
5693 }
5694
5695 //bottom preview
5696 for(int32_t j = bottom_row_y; j < bottom_row_y + tile_size; j++)
5697 {
5698 for(int32_t i=0; i<tiles_across * tile_size; i++)
5699 {
5700 if(((i^j)&1)==0)
5701 {
5702 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5703 }
5704 }
5705 }
5706
5707 //left preview
5708 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5709 {
5710 for(int32_t i=0; i<16*mapscreen_single_scale; i++)
5711 {
5712 if(((i^j)&1)==0)
5713 {
5714 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5715 }
5716 }
5717 }
5718
5719 //right preview
5720 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5721 {
5722 for(int32_t i = right_col_x; i < right_col_x + tile_size; i++)
5723 {
5724 if(((i^j)&1)==0)
5725 {
5726 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5727 }
5728 }
5729 }
5730 }
5731
5732 if(!(Flags&cDEBUG) && pixeldb==2)
5733 {
5734 for(int32_t j=int32_t(168*mapscreen_single_scale); j<int32_t(176*mapscreen_single_scale); j++)
5735 {
5736 for(int32_t i=0; i<int32_t(256*mapscreen_single_scale); i++)
5737 {
5738
5739 if(((i^j)&1)==0)
5740 {
5741 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0)+i),
5742 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5743 }
5744 }
5745 }
5746 }
5747
5748 // TODO: This should move to `zmap::draw` (and delete the current code there doing a similar thing).
5749 if (Map.isDark(Map.getCurrScr()) && Map.getViewSize() == 1)
5750 {
5751 if((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM))
5752 {
5753 BITMAP* tmpDark = create_bitmap_ex(8,16*16,16*11);
5754 BITMAP* tmpDarkTrans = create_bitmap_ex(8,16*16,16*11);
5755 BITMAP* tmpbuf = create_bitmap_ex(8,
5756 mapscreen_single_scale*(256+(showedges?32:0)),
5757 mapscreen_single_scale*(176+(showedges?32:0)));
5758 BITMAP* tmpbuf2 = create_bitmap_ex(8,
5759 mapscreen_single_scale*(256+(showedges?32:0)),
5760 mapscreen_single_scale*(176+(showedges?32:0)));
5761 int32_t darkCol = zinit.darkcol;
5762 switch(darkCol) //special cases
5763 {
5764 case BLACK:
5765 darkCol = vc(0);
5766 break;
5767 case WHITE:
5768 darkCol = vc(15);
5769 break;
5770 }
5771 clear_to_color(tmpDark, darkCol);
5772 clear_to_color(tmpDarkTrans, darkCol);
5773 clear_bitmap(tmpbuf);
5774 clear_bitmap(tmpbuf2);
5775 //Handle torch combos
5776 color_map = &trans_table2;
5777 Map.draw_darkness(tmpDark, tmpDarkTrans);
5778 //
5779 mapscr* tmp = Map.CurrScr();
5780 if(tmp->flags9 & fDARK_DITHER)
5781 {
5782 ditherblit(tmpDark, tmpDark, 0, zinit.dither_type, zinit.dither_arg);
5783 ditherblit(tmpDarkTrans, tmpDarkTrans, 0, zinit.dither_type, zinit.dither_arg);
5784 }
5785
5786 if(mapscreen_single_scale == 1)
5787 {
5788 blit(tmpDark, tmpbuf, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5789 blit(tmpDarkTrans, tmpbuf2, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5790 }
5791 else
5792 {
5793 stretch_blit(tmpDark, tmpbuf, 0, 0, 16*16, 16*11,
5794 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5795 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5796 stretch_blit(tmpDarkTrans, tmpbuf2, 0, 0, 16*16, 16*11,
5797 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5798 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5799 }
5800
5801 if(tmp->flags9 & fDARK_TRANS)
5802 {
5803 draw_trans_sprite(menu1, tmpbuf, mapscreen_x, mapscreen_y);
5804 }
5805 else
5806 {
5807 masked_blit(tmpbuf,menu1,0,0,mapscreen_x,mapscreen_y,tmpbuf->w,tmpbuf->h);
5808 }
5809 draw_trans_sprite(menu1, tmpbuf2, mapscreen_x, mapscreen_y);
5810 color_map = &trans_table;
5811 //
5812 destroy_bitmap(tmpDark);
5813 destroy_bitmap(tmpDarkTrans);
5814 destroy_bitmap(tmpbuf);
5815 destroy_bitmap(tmpbuf2);
5816 }
5817 else if(!(Flags&cNODARK))
5818 {
5819 for(int32_t j=0; j<80*mapscreen_single_scale; j++)
5820 {
5821 for(int32_t i=0; i<(80*mapscreen_single_scale)-j; i++)
5822 {
5823 if(((i^j)&1)==0)
5824 {
5825 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0))+i,
5826 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5827 }
5828 }
5829 }
5830 }
5831 }
5832
5833 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
5834 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
5835 bool inrect = isinRect(gui_mouse_x(),gui_mouse_y(),startx,starty,(startx+(256*mapscreen_screenunit_scale)-1),(starty+(176*mapscreen_screenunit_scale)-1));
5836
5837 if(!(flags&rNOCURSOR) && ((ComboBrush && !ComboBrushPause)||draw_mode==dm_alias) && inrect)
5838 {
5839 int mgridscale=16*mapscreen_single_scale;
5840 if(allowHideMouse)
5841 {
5842 if(arrowcursor)
5843 {
5844 arrowcursor = false;
5845 MouseSprite::set(ZQM_BLANK);
5846 }
5847 }
5848 else if(!arrowcursor)
5849 {
5850 arrowcursor = true;
5851 MouseSprite::set(ZQM_NORMAL);
5852 }
5853 ComboPosition pos = get_mapscreen_mouse_combo_pos();
5854 int32_t mx = pos.x * 16 * mapscreen_single_scale;
5855 int32_t my = pos.y * 16 * mapscreen_single_scale;
5856
5857 clear_bitmap(brushscreen);
5858 int32_t tempbw=BrushWidth;
5859 int32_t tempbh=BrushHeight;
5860
5861 if(draw_mode==dm_alias)
5862 {
5863 BrushWidth = combo_aliases[combo_apos].width+1;
5864 BrushHeight = combo_aliases[combo_apos].height+1;
5865 }
5866 else if(draw_mode == dm_cpool)
5867 {
5868 BrushWidth = BrushHeight = 1;
5869 combo_pool const& pool = combo_pools[combo_pool_pos];
5870 if(pool.valid())
5871 {
5872 int32_t cid = Combo;
5873 int8_t cset = CSet;
5874 pool.get_w_wrap(cid,cset,cpoolbrush_index/16); //divide to reduce speed
5875 put_combo(brushbmp,0,0,cid,cset,Flags&(cFLAGS|cWALK),0);
5876 }
5877 else clear_bitmap(brushbmp);
5878 }
5879 else if (draw_mode == dm_auto)
5880 {
5881 BrushWidth = BrushHeight = 1;
5882 }
5883
5884 stretch_blit(brushbmp, brushscreen, 0, 0, BrushWidth*16, BrushHeight*16, 0, 0, BrushWidth*mgridscale, BrushHeight*mgridscale);
5885 int float_offx = 0;
5886 int float_offy = 0;
5887
5888 if(FloatBrush)
5889 {
5890 float_offx = -SHADOW_DEPTH*mapscreen_single_scale;
5891 float_offy = -SHADOW_DEPTH*mapscreen_single_scale;
5892
5893 //shadow
5894 for(int x = 0; x < SHADOW_DEPTH*mapscreen_single_scale; ++x)
5895 for(int y = 0; y < (BrushHeight*mgridscale) + (SHADOW_DEPTH*mapscreen_single_scale); ++y)
5896 {
5897 if((((x^y)&1)==1) && y < 12*mgridscale)
5898 putpixel(brushscreen,x+(BrushWidth*mgridscale),y,vc(0));
5899 }
5900
5901 for(int x = 0; x < BrushWidth*mgridscale; ++x)
5902 for(int y = 0; y < SHADOW_DEPTH*mapscreen_single_scale; ++y)
5903 {
5904 if((((x^y)&1)==1) && x<16*mgridscale)
5905 putpixel(brushscreen,x,y+(BrushHeight*mgridscale),vc(0));
5906 }
5907 }
5908
5909 if(draw_mode==dm_alias)
5910 {
5911 combo_alias *combo = &combo_aliases[combo_apos];
5912
5913 if(BrushWidth > 1 && (alias_origin & 1)) //right-align
5914 float_offx -= (BrushWidth - 1) * mgridscale;
5915
5916 if(BrushHeight > 1 && (alias_origin & 2)) //bottom-align
5917 float_offy -= (BrushHeight - 1) * mgridscale;
5918 }
5919
5920 int bx = mapscreen_x + mx + float_offx + (showedges?(16*mapscreen_single_scale):0);
5921 int by = mapscreen_y + my + float_offy + (showedges?(16*mapscreen_single_scale):0);
5922 masked_blit(brushscreen, menu1, 0, 0, bx, by, 16*mgridscale, 11*mgridscale);
5923 BrushWidth=tempbw;
5924 BrushHeight=tempbh;
5925 }
5926 else
5927 {
5928 if(!arrowcursor)
5929 {
5930 MouseSprite::set(ZQM_NORMAL);
5931 arrowcursor = true;
5932 }
5933 }
5934
5935 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
5936 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
5937 int endxint = startx + 256*mapscreen_screenunit_scale - 1;
5938 int endyint = starty + 176*mapscreen_screenunit_scale - 1;
5939 set_clip_rect(menu1,startxint,startyint,endxint,endyint);
5940
5941 if(ShowGrid)
5942 {
5943 int w = num_combos_width;
5944 int h = num_combos_height;
5945 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5946
5947 if(showedges)
5948 {
5949 w += 2;
5950 h += 2;
5951 }
5952
5953 for (int x = 1; x < w; x++)
5954 {
5955 vline(menu1, mapscreen_x + x*tile_size, mapscreen_y, mapscreen_y + (h*tile_size)-1, vc(GridColor));
5956 }
5957
5958 for (int y = 1; y < h; y++)
5959 {
5960 hline(menu1, mapscreen_x, mapscreen_y + y*tile_size, mapscreen_x + (w*tile_size)-1, vc(GridColor));
5961 }
5962 }
5963
5964 if(ShowScreenGrid)
5965 {
5966 int w = num_combos_width;
5967 int h = num_combos_height;
5968 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5969 int startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
5970 int starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
5971
5972 if(showedges)
5973 {
5974 w += 1;
5975 h += 1;
5976 }
5977
5978 int color = (GridColor+8)%16;
5979
5980 for (int x = 16; x < w; x+=16)
5981 {
5982 vline(menu1, startx + x*tile_size, mapscreen_y, starty + (h*tile_size)-1, vc(color));
5983 }
5984
5985 for (int y = 11; y < h; y+=11)
5986 {
5987 hline(menu1, startx, starty + y*tile_size, startx + (w*tile_size)-1, vc(color));
5988 }
5989 }
5990
5991 // Draw a rect around regions.
5992 if (ShowRegionGrid && Map.getViewSize() > 1)
5993 {
5994 for (const auto& region_description : Map.get_region_descriptions())
5995 {
5996 int sx = region_description.screen % 16;
5997 int sy = region_description.screen / 16;
5998 int sw = region_description.w;
5999 int sh = region_description.h;
6000
6001 int mw = 256 * mapscreen_single_scale;
6002 int mh = 176 * mapscreen_single_scale;
6003 int mx = sx - (Map.getViewScr() % 16);
6004 int my = sy - (Map.getViewScr() / 16);
6005 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6006 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6007 rect(menu1, x0+2, y0+2, x0 + mw*sw - 2, y0 + mh*sh - 2, vc(1));
6008 rect(menu1, x0+1, y0+1, x0 + mw*sw - 1, y0 + mh*sh - 1, vc(15));
6009 rect(menu1, x0, y0, x0 + mw*sw, y0 + mh*sh, vc(1));
6010 }
6011 }
6012
6013 // Draw a black-yellow-black rect around the currently selected screen.
6014 if (ShowCurScreenOutline && Map.getViewSize() > 1)
6015 {
6016 int mw = 256 * mapscreen_single_scale;
6017 int mh = 176 * mapscreen_single_scale;
6018 int mx = (Map.getCurrScr() % 16) - (Map.getViewScr() % 16);
6019 int my = (Map.getCurrScr() / 16) - (Map.getViewScr() / 16);
6020 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
6021 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
6022 dotted_rect(menu1, x0+2, y0+2, x0 + mw - 2, y0 + mh - 2, vc(1), vc(0));
6023 rect(menu1, x0+1, y0+1, x0 + mw - 1, y0 + mh - 1, vc(14));
6024 dotted_rect(menu1, x0, y0, x0 + mw, y0 + mh, vc(1), vc(0));
6025 }
6026
6027 clear_clip_rect(menu1);
6028
6029 // Map tabs
6030 font = get_custom_font(CFONT_GUI);
6031
6032 map_page[current_mappage].map=Map.getCurrMap();
6033 map_page[current_mappage].screen=Map.getCurrScr();
6034
6035 for(int32_t btn=0; btn<mappage_count; ++btn)
6036 {
6037 char tbuf[15];
6038 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
6039 draw_layer_button(menu1,map_page_bar[btn].x, map_page_bar[btn].y, map_page_bar[btn].w, map_page_bar[btn].h,tbuf,(btn==current_mappage?D_SELECTED:0));
6040 }
6041 }
6042 break;
6043 case rCOMBOS:
6044 {
6045 auto real_h = combolist_window.h;
6046 jwin_draw_frame(menu1,combolist_window.x,combolist_window.y,combolist_window.w,real_h, FR_WIN);
6047 rectfill(menu1,combolist_window.x+2,combolist_window.y+2,combolist_window.x+combolist_window.w-3,combolist_window.y+real_h-3,jwin_pal[jcBOX]);
6048
6049 //Scrollers
6050 for(int32_t c = 0; c < num_combo_cols; ++c)
6051 {
6052 auto& pos = combolistscrollers[c];
6053
6054 { //Scroll up
6055 auto& p = pos.subsquare(0);
6056 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6057
6058 for(int32_t i=0; i<3; i++)
6059 {
6060 hline(menu1, p.x+5-i, p.y+4+i, p.x+5+i, jwin_pal[jcBOXFG]);
6061 }
6062 }
6063
6064 { //Scroll down
6065 auto& p = pos.subsquare(1);
6066 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6067
6068 for(int32_t i=0; i<3; i++)
6069 {
6070 hline(menu1,p.x+5-i,p.y+6-i, p.x+5+i, jwin_pal[jcBOXFG]);
6071 }
6072 }
6073 }
6074
6075 if(draw_mode==dm_alias)
6076 {
6077 if(LinkedScroll)
6078 {
6079 int tmp = current_comboalist;
6080 for(int q = tmp-1; q >= 0; --q)
6081 {
6082 combo_alistpos[q] = combo_alistpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6083 if(combo_alistpos[q] < 0)
6084 {
6085 tmp = 0;
6086 combo_alistpos[0] = 0;
6087 break;
6088 }
6089 }
6090 for(int q = tmp+1; q < num_combo_cols; ++q)
6091 combo_alistpos[q] = combo_alistpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6092 for(int q = 0; q < num_combo_cols; ++q)
6093 if(combo_apos >= combo_alistpos[q] && combo_apos < combo_alistpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6094 {
6095 current_comboalist = q;
6096 break;
6097 }
6098 }
6099 for(int32_t c = 0; c < num_combo_cols; ++c)
6100 {
6101 auto& pos = comboaliaslist[c];
6102 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6103 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6104 }
6105
6106 auto& prev = comboalias_preview;
6107 jwin_draw_frame(menu1, prev.x-2, prev.y-2, prev.w+4, prev.h+4,FR_DEEP);
6108
6109 BITMAP *prv = create_bitmap_ex(8,64,64);
6110 clear_bitmap(prv);
6111 int32_t scalefactor = 1;
6112
6113 for(int32_t j=0; j<num_combo_cols; ++j)
6114 {
6115 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6116 if(combo_alistpos[j] + per_page >= MAXCOMBOALIASES)
6117 combo_alistpos[j] = MAXCOMBOALIASES-per_page;
6118 auto& col = comboaliaslist[j];
6119 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6120 {
6121 draw_combo_alias_thumbnail(menu1, &combo_aliases[combo_alistpos[j]+i],
6122 (i%col.w)*col.xscale+col.x, (i/col.w)*col.yscale+col.y, col.xscale/16);
6123 }
6124
6125 if((combo_aliases[combo_apos].width>7)||(combo_aliases[combo_apos].height>7))
6126 {
6127 scalefactor=4;
6128 }
6129 else if((combo_aliases[combo_apos].width>3)||(combo_aliases[combo_apos].height>3))
6130 {
6131 scalefactor=2;
6132 }
6133
6134
6135 if(j==current_comboalist)
6136 {
6137 stretch_blit(brushbmp, prv, 0,0,scalefactor*64,zc_min(scalefactor*64,176),0,0,64,scalefactor==4?44:64);
6138 blit(prv,menu1,0,0,comboalias_preview.x,comboalias_preview.y,comboalias_preview.w,comboalias_preview.h);
6139
6140 int32_t rect_pos=combo_apos-combo_alistpos[current_comboalist];
6141
6142 if((rect_pos>=0)&&(rect_pos<(combo_alistpos[current_comboalist]+(col.w*col.h))))
6143 {
6144 int selw = col.xscale;
6145 int selh = col.yscale;
6146 int x1 = (rect_pos&(col.w-1))*col.xscale+col.x;
6147 int y1 = (rect_pos/col.w)*col.yscale+col.y;
6148 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6149 }
6150 }
6151 }
6152
6153 destroy_bitmap(prv);
6154 }
6155 else if(draw_mode==dm_cpool)
6156 {
6157 if(LinkedScroll)
6158 {
6159 int tmp = current_cpoollist;
6160 for(int q = tmp-1; q >= 0; --q)
6161 {
6162 combo_pool_listpos[q] = combo_pool_listpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6163 if(combo_pool_listpos[q] < 0)
6164 {
6165 tmp = 0;
6166 combo_pool_listpos[0] = 0;
6167 break;
6168 }
6169 }
6170 for(int q = tmp+1; q < num_combo_cols; ++q)
6171 combo_pool_listpos[q] = combo_pool_listpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6172 for(int q = 0; q < num_combo_cols; ++q)
6173 if(combo_pool_pos >= combo_pool_listpos[q] && combo_pool_pos < combo_pool_listpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6174 {
6175 current_cpoollist = q;
6176 break;
6177 }
6178 }
6179 for(int32_t c = 0; c < num_combo_cols; ++c)
6180 {
6181 auto& pos = comboaliaslist[c];
6182 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6183 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*comboaliaslist[c].xscale)+4,(pos.h*comboaliaslist[c].yscale)+4,FR_DEEP);
6184 }
6185
6186 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6187 {
6188 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6189 if(combo_pool_listpos[j] + per_page >= MAXCOMBOPOOLS)
6190 combo_pool_listpos[j] = MAXCOMBOPOOLS-per_page;
6191 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6192 {
6193 int32_t cid=-1; int8_t cs=CSet;
6194 combo_pool const& cp = combo_pools[combo_pool_listpos[j]+i];
6195
6196 auto& list = comboaliaslist[j];
6197 if(cp.get_w(cid,cs,0) && !combobuf[cid].tile)
6198 {
6199 cid = -1; //no tile to draw
6200 }
6201 auto cx = (i%list.w)*list.xscale+list.x;
6202 auto cy = (i/list.w)*list.yscale+list.y;
6203 put_combo(menu1,cx,cy,cid,cs,Flags&(cFLAGS|cWALK),0,list.xscale/16);
6204 }
6205 }
6206 int32_t rect_pos=combo_pool_pos-combo_pool_listpos[current_cpoollist];
6207
6208 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_cpoollist]+(comboaliaslist[current_cpoollist].w*comboaliaslist[current_cpoollist].h))))
6209 {
6210 int selw = comboaliaslist[current_cpoollist].xscale;
6211 int selh = comboaliaslist[current_cpoollist].yscale;
6212 int x1 = (rect_pos&(comboaliaslist[current_cpoollist].w-1))*comboaliaslist[current_cpoollist].xscale+comboaliaslist[current_cpoollist].x;
6213 int y1 = (rect_pos/comboaliaslist[current_cpoollist].w)*comboaliaslist[current_cpoollist].yscale+comboaliaslist[current_cpoollist].y;
6214 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6215 }
6216
6217 //Handle Preview
6218 combo_pool const& cpool = combo_pools[combo_pool_pos];
6219
6220 int32_t cid; int8_t cs;
6221 size_t total = weighted_cpool ? cpool.getTotalWeight() : cpool.combos.size();
6222 size_t ind = 0;
6223 size_t indw = combopool_preview.w/16;
6224 size_t indh = combopool_preview.h/16;
6225 size_t rows = total ? vbound(total/indw,1,indh) : 0;
6226 if (is_compact)
6227 rows = vbound(rows, 1, 3);
6228 else
6229 rows = vbound(rows, 1, 4);
6230 size_t real_height = rows*16;
6231
6232 cpool_prev_visible = rows > 0;
6233 if(rows)
6234 {
6235 jwin_draw_frame(menu1,combopool_preview.x-2,combopool_preview.y-2,
6236 combopool_preview.w+4,real_height+4,FR_DEEP);
6237 rectfill(menu1,combopool_preview.x,combopool_preview.y,
6238 combopool_preview.x+combopool_preview.w-1,
6239 combopool_preview.y+real_height-1,vc(0));
6240 draw_text_button(menu1,combopool_prevbtn.x,combopool_prevbtn.y,
6241 combopool_prevbtn.w,combopool_prevbtn.h,
6242 weighted_cpool ? "Weighted" : "Unweighted",vc(1),vc(14),0,true);
6243 if(!is_compact)
6244 textprintf_ex(menu1,font,combopool_prevbtn.x+combopool_prevbtn.w+5,
6245 combopool_prevbtn.y,jwin_pal[jcBOXFG],-1,"Preview");
6246 for(auto y = 0; y < real_height; y += 16)
6247 {
6248 for(auto x = 0; x < combopool_preview.w; x += 16, ++ind)
6249 {
6250 auto nx = combopool_preview.x+x, ny = combopool_preview.y+y;
6251 if(ind < total)
6252 {
6253 cs = CSet;
6254 if(weighted_cpool
6255 ? cpool.get_w(cid,cs,ind)
6256 : cpool.get_ind(cid,cs,ind))
6257 {
6258 put_combo(menu1,nx,ny,cid,cs,Flags&(cFLAGS|cWALK),0);
6259 continue;
6260 }
6261 }
6262 //No combo to display
6263 xout(menu1, nx, ny, nx+15, ny+15, vc(15));
6264 }
6265 }
6266 }
6267 }
6268 else if (draw_mode == dm_auto)
6269 {
6270 if (LinkedScroll)
6271 {
6272 int tmp = current_cautolist;
6273 for (int q = tmp - 1; q >= 0; --q)
6274 {
6275 combo_auto_listpos[q] = combo_auto_listpos[q + 1] - (comboaliaslist[q].w * comboaliaslist[q].h);
6276 if (combo_auto_listpos[q] < 0)
6277 {
6278 tmp = 0;
6279 combo_auto_listpos[0] = 0;
6280 break;
6281 }
6282 }
6283 for (int q = tmp + 1; q < num_combo_cols; ++q)
6284 combo_auto_listpos[q] = combo_auto_listpos[q - 1] + (comboaliaslist[q - 1].w * comboaliaslist[q - 1].h);
6285 for (int q = 0; q < num_combo_cols; ++q)
6286 if (combo_auto_pos >= combo_auto_listpos[q] && combo_auto_pos < combo_auto_listpos[q] + (comboaliaslist[q].w * comboaliaslist[q].h))
6287 {
6288 current_cautolist = q;
6289 break;
6290 }
6291 }
6292 for (int32_t c = 0; c < num_combo_cols; ++c)
6293 {
6294 auto& pos = comboaliaslist[c];
6295 rectfill(menu1, pos.x, pos.y, pos.x + (pos.w * pos.xscale) - 1, pos.y + (pos.h * pos.yscale) - 1, 0);
6296 jwin_draw_frame(menu1, pos.x - 2, pos.y - 2, (pos.w * comboaliaslist[c].xscale) + 4, (pos.h * comboaliaslist[c].yscale) + 4, FR_DEEP);
6297 }
6298
6299 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6300 {
6301 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6302 if(combo_auto_listpos[j] + per_page >= MAXAUTOCOMBOS)
6303 combo_auto_listpos[j] = MAXAUTOCOMBOS-per_page;
6304 for (int32_t i = 0; i < (comboaliaslist[j].w * comboaliaslist[j].h); i++)
6305 {
6306 int32_t cid = -1; int8_t cs = CSet;
6307 combo_auto const& ca = combo_autos[combo_auto_listpos[j] + i];
6308
6309 auto& list = comboaliaslist[j];
6310 cid = ca.getDisplay();
6311 if (cid == 0)
6312 cid = -1;
6313 auto cx = (i % list.w) * list.xscale + list.x;
6314 auto cy = (i / list.w) * list.yscale + list.y;
6315 put_combo(menu1, cx, cy, cid, cs, Flags & (cFLAGS | cWALK), 0, list.xscale / 16);
6316 put_autocombo_engravings(menu1, ca, combo_auto_listpos[j] + i == combo_auto_pos, cx, cy, list.xscale / 16);
6317 }
6318 }
6319 int32_t rect_pos = combo_auto_pos - combo_auto_listpos[current_cautolist];
6320
6321 if ((rect_pos >= 0) && (rect_pos < (combo_auto_listpos[current_cautolist] + (comboaliaslist[current_cautolist].w * comboaliaslist[current_cautolist].h))))
6322 {
6323 int selw = comboaliaslist[current_cautolist].xscale;
6324 int selh = comboaliaslist[current_cautolist].yscale;
6325 int x1 = (rect_pos & (comboaliaslist[current_cautolist].w - 1)) * comboaliaslist[current_cautolist].xscale + comboaliaslist[current_cautolist].x;
6326 int y1 = (rect_pos / comboaliaslist[current_cautolist].w) * comboaliaslist[current_cautolist].yscale + comboaliaslist[current_cautolist].y;
6327 safe_rect(menu1, x1, y1, x1 + selw - 1, y1 + selh - 1, vc(CmbCursorCol), 2);
6328
6329 combo_auto const& ca = combo_autos[combo_auto_pos];
6330 put_autocombo_engravings(menu1, ca, true, x1, y1, selw / 16);
6331 }
6332 }
6333 else
6334 {
6335 if(LinkedScroll)
6336 {
6337 int tmp = current_combolist;
6338 for(int q = tmp-1; q >= 0; --q)
6339 {
6340 First[q] = First[q+1]-(combolist[q].w*combolist[q].h);
6341 if(First[q] < 0)
6342 {
6343 tmp = 0;
6344 First[0] = 0;
6345 break;
6346 }
6347 }
6348 for(int q = tmp+1; q < num_combo_cols; ++q)
6349 First[q] = First[q-1]+(combolist[q-1].w*combolist[q-1].h);
6350 for(int q = 0; q < num_combo_cols; ++q)
6351 if(Combo >= First[q] && Combo < First[q] + (combolist[q].w*combolist[q].h))
6352 {
6353 current_combolist = q;
6354 break;
6355 }
6356 }
6357 for(int32_t c = 0; c < num_combo_cols; ++c)
6358 {
6359 auto& pos = combolist[c];
6360 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6361 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6362 }
6363
6364 int32_t drawmap, drawscr;
6365 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6366 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6367
6368 for(int32_t j=0; j<num_combo_cols; ++j)
6369 {
6370 auto per_page = (combolist[j].w * combolist[j].h);
6371 if(First[j] + per_page >= MAXCOMBOS)
6372 First[j] = MAXCOMBOS-per_page;
6373 for(int32_t i=0; i<(combolist[j].w*combolist[j].h); i++)
6374 {
6375 put_combo(menu1,(i%combolist[j].w)*combolist[j].xscale+combolist[j].x,
6376 (i/combolist[j].w)*combolist[j].yscale+combolist[j].y,
6377 i+First[j],CSet,Flags&(cFLAGS|cWALK),0,combolist[j].xscale/16);
6378 }
6379 }
6380
6381 int32_t rect_pos=Combo-First[current_combolist];
6382
6383 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_combolist]+(combolist[current_combolist].w*combolist[current_combolist].h))))
6384 {
6385 int selw = (AutoBrush?BrushWidth:1)*combolist[current_combolist].xscale;
6386 int selh = (AutoBrush?BrushHeight:1)*combolist[current_combolist].yscale;
6387 int x1 = (rect_pos&(combolist[current_combolist].w-1))*combolist[current_combolist].xscale+combolist[current_combolist].x;
6388 int y1 = (rect_pos/combolist[current_combolist].w)*combolist[current_combolist].yscale+combolist[current_combolist].y;
6389 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6390 }
6391 }
6392 }
6393 break;
6394 case rCOMBO:
6395 {
6396 int32_t drawmap, drawscr;
6397 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6398 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6399
6400 // Combo preview
6401 int32_t cid = Combo; int8_t cs = CSet;
6402 if(draw_mode == dm_alias)
6403 {
6404 cid = combo_aliases[combo_apos].combos[0];
6405 cs = wrap(combo_aliases[combo_apos].csets[0]+alias_cset_mod, 0, 13);
6406 }
6407 else if(draw_mode == dm_cpool)
6408 {
6409 combo_pool const& cpool = combo_pools[combo_pool_pos];
6410 cid = 0;
6411 cpool.get_w(cid,cs,0);
6412 }
6413 else if (draw_mode == dm_auto)
6414 {
6415 combo_auto const& cauto = combo_autos[combo_auto_pos];
6416 cid = cauto.getDisplay();
6417 }
6418 static BITMAP *combo_preview_bmp=create_bitmap_ex(8,32,32);
6419 static BITMAP *cycle_preview_bmp=create_bitmap_ex(8,32,32);
6420 // Combo
6421 put_combo(combo_preview_bmp,0,0,cid,cs,Flags&(cFLAGS|cWALK),0);
6422 jwin_draw_frame(menu1,combo_preview.x-2,combo_preview.y-2,combo_preview.w+4,combo_preview.h+4, FR_DEEP);
6423 stretch_blit(combo_preview_bmp, menu1, 0, 0, 16, 16, combo_preview.x, combo_preview.y, combo_preview.w, combo_preview.h);
6424
6425 comboprev_buf[0] = 0;
6426 comboprev_buf2[0] = 0;
6427 if(draw_mode == dm_cpool)
6428 {
6429 sprintf(comboprev_buf,"Pool: %d",combo_pool_pos);
6430 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6431 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],comboprev_buf,2,&combo_preview_text1);
6432 }
6433 else if (draw_mode == dm_auto)
6434 {
6435 GUI::ListData ac_types = GUI::ZCListData::autocombotypes();
6436 std::string type_name = ac_types.findText(combo_autos[combo_auto_pos].getType());
6437 if (is_compact)
6438 sprintf(comboprev_buf, "AC: %d CS: %d\n%s", combo_auto_pos, CSet, type_name.c_str());
6439 else
6440 sprintf(comboprev_buf, "Auto: %d CSet: %d\n%s\nEntries: %d", combo_auto_pos, CSet, type_name.c_str(), int32_t(combo_autos[combo_auto_pos].combos.size()));
6441 int x = combo_preview_text1.x + (combo_preview_text1.w * combo_preview_text1.xscale);
6442 textbox_out(menu1, txfont, x, combo_preview_text1.y, jwin_pal[jcBOXFG], jwin_pal[jcBOX], comboprev_buf, 2, &combo_preview_text1);
6443 }
6444 else if(draw_mode != dm_alias)
6445 {
6446 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6447
6448 char shortbuf[512];
6449 char buf[256];
6450 strcpy(buf,combo_class_buf[combobuf[Combo].type].name);
6451 sprintf(comboprev_buf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6452 int ind = strlen(buf)-1;
6453 int x2 = x;
6454 if(x2 - text_length(txfont, buf) <= combolist_window.x)
6455 {
6456 auto dotlen = text_length(txfont, "..");
6457 x2 -= dotlen;
6458 while(x2 - text_length(txfont, buf) <= combolist_window.x)
6459 {
6460 if(ind < 0) break;
6461 buf[ind--] = '\0';
6462 }
6463 while(ind >= 0 && buf[ind] == ' ')
6464 buf[ind--] = 0; //trim spaces
6465 strcat(buf, "..");
6466 }
6467
6468 if(is_compact)
6469 {
6470 char b2[256];
6471 sprintf(b2, "Combo %d CS %d", Combo, CSet);
6472 if(x-text_length(txfont, b2) <= combolist_window.x)
6473 sprintf(b2, "Cmb %d CS %d", Combo, CSet);
6474 sprintf(shortbuf,"%s\n%s",b2,buf);
6475 }
6476 else sprintf(shortbuf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6477 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,2,&combo_preview_text1);
6478 }
6479
6480 // Cycle
6481 if(!is_compact)
6482 {
6483 int32_t NextCombo = combobuf[Combo].nextcombo;
6484 int32_t NextCSet = combobuf[Combo].nextcset;
6485 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
6486 {
6487 mapscr* scr = Map.CurrScr();
6488 NextCombo = scr->undercombo;
6489 NextCSet = scr->undercset;
6490 }
6491 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
6492 NextCSet = CSet;
6493 bool normal_dm = draw_mode != dm_alias && draw_mode != dm_cpool && draw_mode != dm_auto;
6494 jwin_draw_frame(menu1,combo_preview2.x-2,combo_preview2.y-2,combo_preview2.w+4,combo_preview2.h+4, FR_DEEP);
6495 if(NextCombo>0 && normal_dm)
6496 {
6497 put_combo(cycle_preview_bmp,0,0,NextCombo,NextCSet,Flags&(cFLAGS|cWALK),0);
6498
6499 if(Flags&cWALK) put_walkflags(cycle_preview_bmp,0,0,NextCombo,0);
6500
6501 if(Flags&cFLAGS) put_flags(cycle_preview_bmp,0,0,NextCombo,0,cFLAGS,0);
6502
6503 stretch_blit(cycle_preview_bmp, menu1, 0, 0, 16, 16, combo_preview2.x, combo_preview2.y, combo_preview2.w, combo_preview2.h);
6504 }
6505 else
6506 {
6507 if (InvalidBG == 2)
6508 {
6509 draw_checkerboard(menu1, combo_preview2.x, combo_preview2.y, 32);
6510 }
6511 else if(InvalidBG == 1)
6512 {
6513 for(int32_t dy=0; dy<combo_preview2.w; dy++)
6514 {
6515 for(int32_t dx=0; dx<combo_preview2.w; dx++)
6516 {
6517 menu1->line[dy+combo_preview2.y][dx+combo_preview2.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6518 }
6519 }
6520 }
6521 else
6522 {
6523 rectfill(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(0));
6524 safe_rect(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6525 line(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6526 line(menu1, combo_preview2.x,combo_preview2.y+combo_preview2.h, combo_preview2.x+32,combo_preview2.y,vc(15));
6527 }
6528 }
6529
6530 if(normal_dm)
6531 {
6532 char shortbuf[512];
6533 char buf[256];
6534 strcpy(buf,combo_class_buf[combobuf[NextCombo].type].name);
6535 sprintf(comboprev_buf2, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6536 int ind = strlen(buf)-1;
6537 int x2 = combo_preview_text2.x;
6538 if(x2 + text_length(txfont, buf) > zq_screen_w-2)
6539 {
6540 auto dotlen = text_length(txfont, "..");
6541 x2 += dotlen;
6542 while(x2 + text_length(txfont, buf) > zq_screen_w-2)
6543 {
6544 if(ind < 0) break;
6545 buf[ind--] = '\0';
6546 }
6547 while(ind >= 0 && buf[ind] == ' ')
6548 buf[ind--] = 0; //trim spaces
6549 strcat(buf, "..");
6550 }
6551
6552 sprintf(shortbuf, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6553 textbox_out(menu1,txfont,combo_preview_text2.x,combo_preview_text2.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,0,&combo_preview_text2);
6554 }
6555 }
6556
6557 font = get_zc_font(font_lfont_l);
6558 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
6559 draw_text_button(menu1,combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<",vc(1),vc(14),0,true);
6560 }
6561 break;
6562 case rFAVORITES:
6563 {
6564 font = get_zc_font(font_lfont_l);
6565
6566 jwin_draw_frame(menu1,favorites_window.x,favorites_window.y,favorites_window.w,favorites_window.h, FR_WIN);
6567 rectfill(menu1,favorites_window.x+2,favorites_window.y+2,favorites_window.x+favorites_window.w-3,favorites_window.y+favorites_window.h-3,jwin_pal[jcBOX]);
6568 jwin_draw_frame(menu1,favorites_list.x-2,favorites_list.y-2,(favorites_list.w*favorites_list.xscale)+4,(favorites_list.h*favorites_list.yscale)+4, FR_DEEP);
6569 rectfill(menu1,favorites_list.x,favorites_list.y,favorites_list.x+(favorites_list.w*favorites_list.xscale)-1,favorites_list.y+(favorites_list.h*favorites_list.yscale)-1,jwin_pal[jcBOXFG]);
6570
6571 textprintf_ex(menu1,get_zc_font(font_lfont_l),favorites_list.x-2,favorites_list.y-15,jwin_pal[jcBOXFG],-1,is_compact ? "Favorites" : "Favorite Combos");
6572 BITMAP* subb = create_bitmap_ex(8,16,16);
6573
6574 for(int32_t col=0; col<favorites_list.w; ++col)
6575 {
6576 for(int32_t row=0; row<favorites_list.h; ++row)
6577 {
6578 auto i = (row*FAVORITECOMBO_PER_ROW)+col+FAVORITECOMBO_PER_PAGE*FavoriteComboPage;
6579 auto& sqr = favorites_list.subsquare(col,row);
6580 if(i >= MAXFAVORITECOMBOS || favorite_combos[i]==-1)
6581 {
6582 if (InvalidBG == 2)
6583 {
6584 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
6585 }
6586 else if(InvalidBG == 1)
6587 {
6588 for(int32_t dy=0; dy<sqr.h; dy++)
6589 {
6590 for(int32_t dx=0; dx<sqr.w; dx++)
6591 {
6592 menu1->line[sqr.y+dy][sqr.x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6593 }
6594 }
6595 }
6596 else
6597 {
6598 xout(menu1, sqr.x, sqr.y, sqr.x+sqr.w-1, sqr.y+sqr.h-1, vc(15), vc(0));
6599 }
6600 }
6601 else
6602 {
6603 clear_bitmap(subb);
6604 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
6605
6606 switch(favorite_combo_modes[i])
6607 {
6608 case dm_alias:
6609 draw_combo_alias_thumbnail(subb, &combo_aliases[favorite_combos[i]], 0, 0, 1);
6610 if (ShowFavoriteComboModes)
6611 put_engraving(subb, 0, 0, 0x3E, 1);
6612 break;
6613 case dm_cpool:
6614 {
6615 int32_t cid = -1; int8_t cs = CSet;
6616 combo_pool const& cp = combo_pools[favorite_combos[i]];
6617
6618 if (cp.get_w(cid, cs, 0) && !combobuf[cid].tile)
6619 cid = -1; //no tile to draw
6620 put_combo(subb, 0, 0, cid, cs, 0, 0);
6621 if (ShowFavoriteComboModes)
6622 put_engraving(subb, 0, 0, 0x3D, 1);
6623 break;
6624 }
6625 case dm_auto:
6626 {
6627 int32_t cid = -1; int8_t cs = CSet;
6628 combo_auto const& ca = combo_autos[favorite_combos[i]];
6629
6630 cid = ca.getDisplay();
6631 if (cid == 0)
6632 cid = -1;
6633 put_combo(subb, 0, 0, cid, cs, 0, 0);
6634 if (ShowFavoriteComboModes)
6635 put_engraving(subb, 0, 0, 0x3C, 1);
6636 break;
6637 }
6638 default:
6639 if (repos)
6640 {
6641 combotile_override_x = sqr.x + (sqr.w - 16) / 2;
6642 combotile_override_y = sqr.y + (sqr.h - 16) / 2;
6643 }
6644 put_combo(subb, 0, 0, favorite_combos[i], CSet, Flags & (cFLAGS | cWALK), 0);
6645 if (repos) combotile_override_x = combotile_override_y = -1;
6646 }
6647 stretch_blit(subb, menu1, 0, 0, 16, 16, sqr.x, sqr.y, sqr.w, sqr.h);
6648 }
6649 }
6650 }
6651
6652 destroy_bitmap(subb);
6653
6654 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
6655 if(!is_compact)
6656 textprintf_right_ex(menu1, get_zc_font(font_lfont_l), favorites_pgleft.x - 2, favorites_pgleft.y, jwin_pal[jcBOXFG], -1, "%d/9", FavoriteComboPage + 1);
6657
6658 draw_text_button(menu1, favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-", vc(1), vc(14), 0, true);
6659 draw_text_button(menu1, favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->", vc(1), vc(14), 0, true);
6660 draw_text_button(menu1,favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6661 draw_text_button(menu1,favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X",vc(1),vc(14),0,true);
6662 draw_text_button(menu1,favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?",vc(1),vc(14),0,true);
6663 }
6664 break;
6665 case rCOMMANDS:
6666 {
6667 jwin_draw_frame(menu1,commands_window.x,commands_window.y,commands_window.w,commands_window.h, FR_WIN);
6668 rectfill(menu1,commands_window.x+2,commands_window.y+2,commands_window.x+commands_window.w-3,commands_window.y+commands_window.h-3,jwin_pal[jcBOX]);
6669 jwin_draw_frame(menu1,commands_list.x-2,commands_list.y-2,(commands_list.w*commands_list.xscale)+4,(commands_list.h*commands_list.yscale)+4, FR_DEEP);
6670 rectfill(menu1,commands_list.x,commands_list.y,commands_list.x+(commands_list.w*commands_list.xscale)-1,commands_list.y+(commands_list.h*commands_list.yscale)-1,jwin_pal[jcBOXFG]);
6671 font=get_custom_font(CFONT_FAVCMD);
6672
6673 for(int32_t cmd=0; cmd<(commands_list.w*commands_list.h); ++cmd)
6674 {
6675 uint hkey = favorite_commands[cmd];
6676 draw_layer_button(menu1,
6677 (cmd%commands_list.w)*commands_list.xscale+commands_list.x,
6678 (cmd/commands_list.w)*commands_list.yscale+commands_list.y,
6679 commands_list.xscale,
6680 commands_list.yscale,
6681 get_hotkey_name(hkey),
6682 (selected_hotkey(hkey)?D_SELECTED:0) | (disabled_hotkey(hkey)?D_DISABLED:0));
6683 }
6684
6685 font = get_zc_font(font_lfont_l);
6686 if(commands_txt.x > 0)
6687 {
6688 gui_textout_ln(menu1, get_zc_font(font_lfont_l), (ucc*)"Favorite Commands", commands_txt.x, commands_txt.y, jwin_pal[jcBOXFG], -1, 0);
6689 }
6690
6691 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
6692 draw_text_button(menu1,commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6693 draw_text_button(menu1,commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X",vc(1),vc(14),0,true);
6694 draw_text_button(menu1,commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?",vc(1),vc(14),0,true);
6695 }
6696 break;
6697 }
6698 font = tfont;
6699 }
6700
6701 bool pause_refresh = true;
6702 bool is_refreshing = false;
6703 11 void refresh(int32_t flags, bool update)
6704 {
6705
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(pause_refresh) return;
6706 static bool refreshing = false;
6707
6708 int num_screens_to_draw = Map.getViewSize();
6709
6710 bool earlyret = refreshing;
6711 is_refreshing = refreshing = true;
6712 //^ These prevent recursive calls from updating the screen early
6713
6714 bool zoom_delay = (zoomed_minimap && flags != rSCRMAP);
6715 if(zoom_delay)
6716 flags &= ~rSCRMAP;
6717
6718 if(flags&rCLEAR)
6719 {
6720 //magic pink = 0xED
6721 //system black = vc(0)
6722 //Clear a4 menu
6723 clear_to_color(menu1,jwin_pal[jcBOX]);
6724
6725 //Clears should refresh everything!
6726 flags |= rALL;
6727 }
6728
6729 if(flags&rSCRMAP)
6730 draw_screenunit(rSCRMAP,flags);
6731
6732 if(flags&rMAP)
6733 draw_screenunit(rMAP,flags);
6734
6735 if((flags&rCOMBOS) || (draw_mode == dm_cpool && (flags&rFAVORITES)))
6736 draw_screenunit(rCOMBOS,flags);
6737
6738 if(flags&(rCOMBO|rCOMBOS))
6739 draw_screenunit(rCOMBO,flags);
6740
6741 if(flags&rMENU)
6742 drawpanel();
6743
6744 if(flags&rFAVORITES)
6745 draw_screenunit(rFAVORITES,flags);
6746
6747 if(flags&rCOMMANDS)
6748 draw_screenunit(rCOMMANDS,flags);
6749
6750 FONT* tfont = font;
6751 font = get_custom_font(CFONT_GUI);
6752 jwin_draw_frame(menu1,layer_panel.x,layer_panel.y,layer_panel.w,layer_panel.h,FR_DEEP);
6753 rectfill(menu1,layer_panel.x,layer_panel.y,layer_panel.x+layer_panel.w-1,layer_panel.y+layer_panel.h-1,jwin_pal[jcBOX]);
6754
6755 for(int32_t i=0; i<=6; ++i)
6756 {
6757 char tbuf[15];
6758
6759 if (i>0 && mapscreen_valid_layers[i - 1] && num_screens_to_draw == 1)
6760 {
6761 if(is_compact)
6762 sprintf(tbuf, "%s%d %d:%02X", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6763 else sprintf(tbuf, "%s%d (%d:%02X)", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6764 }
6765 else
6766 {
6767 sprintf(tbuf, "%s%d", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i);
6768 }
6769
6770 int32_t spacing_offs = is_compact ? 2 : 10;
6771 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
6772 int32_t ry = layer_panel.y;
6773 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
6774 draw_layer_button(menu1, rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf, CurrentLayer==i? D_SELECTED : ( i > 0 && !mapscreen_valid_layers[i-1]) ? D_DISABLED : 0);
6775 draw_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]!=0);
6776 }
6777
6778 font=tfont;
6779
6780 // } //if(true)
6781 if(zq_showpal)
6782 {
6783 for(int32_t i=0; i<256; i++)
6784 {
6785 rectfill(menu1,((i&15)<<2)+256,((i>>4)<<2)+176,((i&15)<<2)+259,((i>>4)<<2)+179,i);
6786 }
6787 }
6788 { //Show top-left info
6789 size_t maxwid = (mapscreen_screenunit_scale*mapscreenbmp->w)-1;
6790 size_t maxhei = (mapscreen_screenunit_scale*mapscreenbmp->w);
6791 set_clip_rect(menu1,mapscreen_x,mapscreen_y,mapscreen_x+maxwid-1,mapscreen_y+maxhei-1);
6792 FONT* showfont = get_custom_font(CFONT_INFO);
6793 int showfont_h = text_height(showfont);
6794 int32_t ypos = mapscreen_y;
6795 if(prv_mode)
6796 {
6797 textout_shadowed_ex(menu1,showfont,"Preview Mode",0,ypos,vc(15),vc(0),infobg?vc(0):-1);
6798 ypos += showfont_h+1;
6799 if(prv_twon)
6800 {
6801 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"T Warp=%d tics", Map.get_prvtime());
6802 ypos += showfont_h+1;
6803 }
6804 }
6805 if(ShowFPS)
6806 {
6807 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"FPS: %3d",lastfps);
6808 ypos += showfont_h+1;
6809 }
6810
6811 if(ShowFFScripts && !prv_mode)
6812 {
6813 word num_ffcs = Map.CurrScr()->numFFC();
6814 for(word i=0; i< num_ffcs; i++)
6815 {
6816 if(ypos+showfont_h-1 > map_page_bar[0].y)
6817 break;
6818 if(Map.CurrScr()->ffcs[i].script && Map.CurrScr()->ffcs[i].data)
6819 {
6820 textout_shadowed_ex(menu1, showfont, ffcmap[Map.CurrScr()->ffcs[i].script-1].scriptname.substr(0,300).c_str(),0,ypos,vc(showxypos_ffc==i ? 14 : 15),vc(0),infobg?vc(0):-1);
6821 ypos+=showfont_h+1;
6822 }
6823 }
6824 }
6825 clear_clip_rect(menu1);
6826 if(prv_mode)
6827 do_previewtext();
6828 }
6829 // Show Errors & Details
6830 //This includes the presence of: Screen State Carryover, Timed Warp, Maze Path, the 'Sideview Gravity', 'Invisible Hero',
6831 //'Save Screen', 'Continue Here' and 'Treat As..' Screen Flags,
6832 // the String, every Room Type and Catch All, and all four Tile and Side Warps.
6833 if(!prv_mode && ShowInfo)
6834 {
6835 int32_t i=0;
6836 char buf[2048];
6837
6838 // Start with general information
6839 if(Map.CurrScr()->flags3&fINVISHERO)
6840 {
6841 sprintf(buf,"Invisible Hero");
6842 show_screen_error(buf,i++,vc(15));
6843 }
6844
6845 if(Map.getLayerTargetMap() > 0)
6846 {
6847 Map.setlayertarget(); //Now the text does not carry over when changing maps, but shifting back, it does not **re-appear** until you change screens.
6848 //It was also required to set some updates in onDecMap and onIncMap. #
6849 //This fixes Screen Info not displaying properly when changing maps. -Z
6850 //Needed to refresh the screen info. -Z ( 26th March, 2019 )
6851 int32_t m = Map.getLayerTargetMultiple();
6852 sprintf(buf,"Used as a layer by screen %d:%02X",Map.getLayerTargetMap(),Map.getLayerTargetScr());
6853 char buf2[24];
6854
6855 if(m>0)
6856 {
6857 sprintf(buf2," and %d other%s",m,m>1?"s":"");
6858 strcat(buf,buf2);
6859 }
6860
6861 show_screen_error(buf,i++,vc(15));
6862 }
6863
6864 if(Map.CurrScr()->nextmap)
6865 {
6866 sprintf(buf,"Screen State carries over to %d:%02X",Map.CurrScr()->nextmap,Map.CurrScr()->nextscr);
6867 show_screen_error(buf,i++,vc(15));
6868 }
6869
6870 if(Map.CurrScr()->timedwarptics)
6871 {
6872 sprintf(buf,"%s%sTimed Warp: %s",(Map.CurrScr()->flags4&fTIMEDDIRECT)?"Direct ":"",(Map.CurrScr()->flags5&fRANDOMTIMEDWARP)?"Random ":"",ticksstr(Map.CurrScr()->timedwarptics));
6873 show_screen_error(buf,i++,vc(15));
6874 }
6875
6876 if(Map.CurrScr()->flags&fMAZE)
6877 {
6878 sprintf(buf,"Maze Path: %s (Exit %s)",pathstr(Map.CurrScr()->path),mazedirstr[Map.CurrScr()->exitdir]);
6879 show_screen_error(buf,i++,vc(15));
6880 }
6881
6882 bool continuescreen = false, savecombo = false;
6883
6884 if(Map.CurrScr()->flags4&fAUTOSAVE)
6885 {
6886 sprintf(buf,"Automatic Save%s Screen", (Map.CurrScr()->flags6&fCONTINUEHERE) ? "-Continue":"");
6887 show_screen_error(buf,i++,vc(15));
6888 continuescreen = ((Map.CurrScr()->flags6&fCONTINUEHERE)!=0);
6889 savecombo = true;
6890 }
6891 else if(Map.CurrScr()->flags6&fCONTINUEHERE)
6892 {
6893 sprintf(buf,"Continue Screen");
6894 show_screen_error(buf,i++,vc(15));
6895 continuescreen = true;
6896 }
6897
6898 if(isSideViewGravity())
6899 {
6900 sprintf(buf,"Sideview Gravity");
6901 show_screen_error(buf,i++,vc(15));
6902 }
6903
6904 if(Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM))
6905 {
6906 sprintf(buf,"Treat As %s%s Screen", (Map.CurrScr()->flags6&fCAVEROOM) ? "Interior":"NES Dungeon",
6907 (Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM)) == (fCAVEROOM|fDUNGEONROOM) ? " or NES Dungeon":"");
6908 show_screen_error(buf,i++,vc(15));
6909 }
6910
6911 if(Map.CurrScr()->oceansfx != 0)
6912 {
6913 sprintf(buf,"Ambient Sound: %s",sfx_string[Map.CurrScr()->oceansfx]);
6914 show_screen_error(buf,i++,vc(15));
6915 }
6916
6917 if(Map.CurrScr()->bosssfx != 0)
6918 {
6919 sprintf(buf,"Boss Roar Sound: %s",sfx_string[Map.CurrScr()->bosssfx]);
6920 show_screen_error(buf,i++,vc(15));
6921 }
6922
6923 if(Map.CurrScr()->str)
6924 {
6925 strncpy(buf,MsgString(Map.CurrScr()->str, true, false),72);
6926 buf[72] = '\0';
6927 char shortbuf[72];
6928 strip_extra_spaces(buf);
6929 shorten_string(shortbuf, buf, get_zc_font(font_lfont_l), 72, 280);
6930 sprintf(buf,"String %s",shortbuf);
6931 show_screen_error(buf,i++,vc(15));
6932 }
6933
6934 if((Map.CurrScr()->flags&fWHISTLE) || (Map.CurrScr()->flags7&fWHISTLEWATER))
6935 {
6936 sprintf(buf,"Whistle ->%s%s%s",(Map.CurrScr()->flags&fWHISTLE)?" Stairs":"",
6937 (Map.CurrScr()->flags&fWHISTLE && Map.CurrScr()->flags7&fWHISTLEWATER)?", ":"",
6938 (Map.CurrScr()->flags7&fWHISTLEWATER)?"Dry Lake":"");
6939 show_screen_error(buf,i++,vc(15));
6940 }
6941
6942 switch(Map.CurrScr()->room)
6943 {
6944 case rSP_ITEM:
6945 sprintf(buf,"Special Item is %s",item_string[Map.CurrScr()->catchall]);
6946 show_screen_error(buf,i++, vc(15));
6947 break;
6948
6949 case rINFO:
6950 {
6951 int32_t shop = Map.CurrScr()->catchall;
6952 sprintf(buf,"Pay For Info: -%d, -%d, -%d",
6953 QMisc.info[shop].price[0],QMisc.info[shop].price[1],QMisc.info[shop].price[2]);
6954 show_screen_error(buf,i++, vc(15));
6955 }
6956 break;
6957
6958 case rMONEY:
6959 sprintf(buf,"Secret Money: %d Rupees",Map.CurrScr()->catchall);
6960 show_screen_error(buf,i++, vc(15));
6961 break;
6962
6963 case rGAMBLE:
6964 show_screen_error("Gamble Room",i++, vc(15));
6965 break;
6966
6967 case rREPAIR:
6968 sprintf(buf,"Door Repair: -%d Rupees",Map.CurrScr()->catchall);
6969 show_screen_error(buf,i++, vc(15));
6970 break;
6971
6972 case rRP_HC:
6973 sprintf(buf,"Take %s or %s", item_string[iRPotion], item_string[iHeartC]);
6974 show_screen_error(buf,i++, vc(15));
6975 break;
6976
6977 case rGRUMBLE:
6978 show_screen_error("Feed the Goriya",i++, vc(15));
6979 break;
6980
6981 case rTRIFORCE:
6982 show_screen_error("Triforce Check",i++, vc(15));
6983 break;
6984
6985 case rP_SHOP:
6986 case rSHOP:
6987 {
6988 int32_t shop = Map.CurrScr()->catchall;
6989 sprintf(buf,"%sShop: ",
6990 Map.CurrScr()->room==rP_SHOP ? "Potion ":"");
6991
6992 for(int32_t j=0; j<3; j++) if(QMisc.shop[shop].item[j]>0) // Print the 3 items and prices
6993 {
6994 strcat(buf,item_string[QMisc.shop[shop].item[j]]);
6995 strcat(buf,":");
6996 char pricebuf[8];
6997 sprintf(pricebuf,"%d",QMisc.shop[shop].price[j]);
6998 strcat(buf,pricebuf);
6999
7000 if(j<2 && QMisc.shop[shop].item[j+1]>0) strcat(buf,", ");
7001 }
7002
7003 show_screen_error(buf,i++, vc(15));
7004 }
7005 break;
7006
7007 case rBOTTLESHOP:
7008 {
7009 int32_t shop = Map.CurrScr()->catchall;
7010 sprintf(buf,"Bottle Shop: ");
7011
7012 for(int32_t j=0; j<3; j++) if(QMisc.bottle_shop_types[shop].fill[j]>0) // Print the 3 fills and prices
7013 {
7014 strcat(buf,QMisc.bottle_types[QMisc.bottle_shop_types[shop].fill[j]-1].name);
7015 strcat(buf,":");
7016 char pricebuf[8];
7017 sprintf(pricebuf,"%d",QMisc.bottle_shop_types[shop].price[j]);
7018 strcat(buf,pricebuf);
7019
7020 if(j<2 && QMisc.bottle_shop_types[shop].fill[j+1]>0) strcat(buf,", ");
7021 }
7022
7023 show_screen_error(buf,i++, vc(15));
7024 }
7025 break;
7026
7027 case rTAKEONE:
7028 {
7029 int32_t shop = Map.CurrScr()->catchall;
7030 sprintf(buf,"Take Only One: %s%s%s%s%s",
7031 QMisc.shop[shop].item[0]<1?"":item_string[QMisc.shop[shop].item[0]],QMisc.shop[shop].item[0]>0?", ":"",
7032 QMisc.shop[shop].item[1]<1?"":item_string[QMisc.shop[shop].item[1]],(QMisc.shop[shop].item[1]>0&&QMisc.shop[shop].item[2]>0)?", ":"",
7033 QMisc.shop[shop].item[2]<1?"":item_string[QMisc.shop[shop].item[2]]);
7034 show_screen_error(buf,i++, vc(15));
7035 }
7036 break;
7037
7038 case rBOMBS:
7039 sprintf(buf,"More Bombs: -%d Rupees",Map.CurrScr()->catchall);
7040 show_screen_error(buf,i++, vc(15));
7041 break;
7042
7043 case rARROWS:
7044 sprintf(buf,"More Arrows: -%d Rupees",Map.CurrScr()->catchall);
7045 show_screen_error(buf,i++, vc(15));
7046 break;
7047
7048 case rSWINDLE:
7049 sprintf(buf,"Leave Life or %d Rupees",Map.CurrScr()->catchall);
7050 show_screen_error(buf,i++, vc(15));
7051 break;
7052
7053 case r10RUPIES:
7054 show_screen_error("10 Rupees",i++, vc(15));
7055 break;
7056
7057 case rGANON:
7058 show_screen_error("Ganon Room",i++, vc(15));
7059 break;
7060
7061 case rZELDA:
7062 show_screen_error("Zelda Room",i++, vc(15));
7063 break;
7064
7065 case rMUPGRADE:
7066 show_screen_error("1/2 Magic Upgrade",i++, vc(15));
7067 break;
7068
7069 case rLEARNSLASH:
7070 show_screen_error("Learn Slash",i++, vc(15));
7071 break;
7072
7073 case rWARP:
7074 sprintf(buf,"3-Stair Warp: Warp Ring %d",Map.CurrScr()->catchall);
7075 show_screen_error(buf,i++, vc(15));
7076 break;
7077 }
7078
7079 bool undercombo = false, warpa = false, warpb = false, warpc = false, warpd = false, warpr = false;
7080
7081 word num_ffcs = Map.CurrScr()->numFFC();
7082 for(int32_t c=0; c<176+128+1+num_ffcs; ++c)
7083 {
7084 // Checks both combos, secret combos, undercombos and FFCs
7085 //Fixme:
7086 int32_t ctype =
7087 combobuf[vbound(
7088 (c>=305 ? Map.CurrScr()->ffcs[c-305].data :
7089 c>=304 ? Map.CurrScr()->undercombo :
7090 c>=176 ? Map.CurrScr()->secretcombo[c-176] :
7091 !Map.CurrScr()->valid ? 0 : // Sanity check: does room combo data exist?
7092 Map.CurrScr()->data[c]
7093 ), 0, MAXCOMBOS-1)].type;
7094
7095 if(!undercombo && integrityBoolUnderCombo(Map.CurrScr(),ctype))
7096 {
7097 undercombo = true;
7098 show_screen_error("Under Combo is combo 0",i++, vc(7));
7099 }
7100
7101 // Tile Warp types
7102 switch(ctype)
7103 {
7104 case cSAVE:
7105 case cSAVE2:
7106 if(!savecombo)
7107 {
7108 savecombo = true;
7109
7110 if(integrityBoolSaveCombo(Map.CurrScr(),ctype))
7111 show_screen_error("Save Screen",i++, vc(15));
7112 else
7113 show_screen_error("Save-Continue Screen",i++, vc(15));
7114 }
7115
7116 break;
7117
7118 case cSTAIRR:
7119 case cPITR:
7120 case cSWARPR:
7121 if(!warpr && (Map.CurrScr()->tilewarptype[0]==wtCAVE || Map.CurrScr()->tilewarptype[1]==wtCAVE ||
7122 Map.CurrScr()->tilewarptype[2]==wtCAVE || Map.CurrScr()->tilewarptype[3]==wtCAVE))
7123 {
7124 warpr = true;
7125 show_screen_error("Random Tile Warp contains Cave/Item Cellar",i++, vc(7));
7126 }
7127
7128 break;
7129
7130 case cCAVED:
7131 case cPITD:
7132 case cSTAIRD:
7133 case cCAVE2D:
7134 case cSWIMWARPD:
7135 case cDIVEWARPD:
7136 case cSWARPD:
7137 if(!warpd)
7138 {
7139 warpd = true;
7140 tile_warp_notification(3,buf);
7141 show_screen_error(buf,i++, vc(15));
7142 }
7143
7144 break;
7145
7146 case cCAVEC:
7147 case cPITC:
7148 case cSTAIRC:
7149 case cCAVE2C:
7150 case cSWIMWARPC:
7151 case cDIVEWARPC:
7152 case cSWARPC:
7153 if(!warpc)
7154 {
7155 warpc = true;
7156 tile_warp_notification(2,buf);
7157 show_screen_error(buf,i++, vc(15));
7158 }
7159
7160 break;
7161
7162 case cCAVEB:
7163 case cPITB:
7164 case cSTAIRB:
7165 case cCAVE2B:
7166 case cSWIMWARPB:
7167 case cDIVEWARPB:
7168 case cSWARPB:
7169 if(!warpb)
7170 {
7171 warpb = true;
7172 tile_warp_notification(1,buf);
7173 show_screen_error(buf,i++, vc(15));
7174 }
7175
7176 break;
7177
7178 case cCAVE:
7179 case cPIT:
7180 case cSTAIR:
7181 case cCAVE2:
7182 case cSWIMWARP:
7183 case cDIVEWARP:
7184 case cSWARPA:
7185 if(!warpa)
7186 {
7187 warpa = true;
7188 tile_warp_notification(0,buf);
7189 show_screen_error(buf,i++, vc(15));
7190 }
7191
7192 break;
7193 }
7194 }
7195
7196 int32_t sidewarpnotify = 0;
7197
7198 if(Map.CurrScr()->flags2&wfUP)
7199 {
7200 side_warp_notification(Map.CurrScr()->sidewarpindex&3,0,buf);
7201 show_screen_error(buf,i++, vc(15));
7202 sidewarpnotify|=(1<<(Map.CurrScr()->sidewarpindex&3));
7203 }
7204
7205 if(Map.CurrScr()->flags2&wfDOWN)
7206 {
7207 side_warp_notification((Map.CurrScr()->sidewarpindex>>2)&3,1,buf);
7208 show_screen_error(buf,i++, vc(15));
7209 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>2)&3));
7210 }
7211
7212 if(Map.CurrScr()->flags2&wfLEFT)
7213 {
7214 side_warp_notification((Map.CurrScr()->sidewarpindex>>4)&3,2,buf);
7215 show_screen_error(buf,i++, vc(15));
7216 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>4)&3));
7217 }
7218
7219 if(Map.CurrScr()->flags2&wfRIGHT)
7220 {
7221 side_warp_notification((Map.CurrScr()->sidewarpindex>>6)&3,3,buf);
7222 show_screen_error(buf,i++, vc(15));
7223 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>6)&3));
7224 }
7225
7226 if(!(sidewarpnotify&1) && Map.CurrScr()->timedwarptics)
7227 {
7228 side_warp_notification(0,4,buf); // Timed Warp
7229 show_screen_error(buf,i++, vc(15));
7230 }
7231
7232 // Now for errors
7233 if((Map.CurrScr()->flags4&fSAVEROOM) && !savecombo) show_screen_error("Save Point->Continue Here, but no Save Point combo?",i++, vc(14));
7234
7235 if(integrityBoolEnemiesItem(Map.CurrScr())) show_screen_error("Enemies->Item, but no enemies",i++, vc(7));
7236
7237 if(integrityBoolEnemiesSecret(Map.CurrScr())) show_screen_error("Enemies->Secret, but no enemies",i++, vc(7));
7238
7239 if(integrityBoolGuyNoString(Map.CurrScr())) show_screen_error("Non-Fairy Guy, but String is (none)",i++, vc(14));
7240
7241 if(integrityBoolRoomNoGuy(Map.CurrScr())) show_screen_error("Guy is (none)",i++, vc(14));
7242
7243 if(integrityBoolRoomNoString(Map.CurrScr())) show_screen_error("String is (none)",i++, vc(14));
7244
7245 if(integrityBoolRoomNoGuyNoString(Map.CurrScr())) show_screen_error("Guy and String are (none)",i++, vc(14));
7246 }
7247
7248 if(zoom_delay)
7249 draw_screenunit(rSCRMAP,flags);
7250
7251
7252 if(flags&rCLEAR)
7253 {
7254 //Draw the whole gui
7255 blit(menu1,screen,0,0,0,0,zq_screen_w,zq_screen_h);
7256 }
7257 else
7258 {
7259 blit(menu1,screen,0,16,0,16,zq_screen_w,zq_screen_h-16);
7260 blit(menu1,screen,combolist_window.x-64,0,combolist_window.x-64,0,combolist_window.w+64,16);
7261
7262 if(flags&rCOMBO)
7263 blit(menu1,screen,combo_preview.x,combo_preview.y,combo_preview.x,combo_preview.y,combo_preview.w,combo_preview.h);
7264 }
7265
7266 if(earlyret)
7267 return;
7268
7269 //Draw the Main Menu
7270 rectfill(screen,mainbar.x,mainbar.y,mainbar.x+mainbar.w-1,mainbar.y+mainbar.h-1,jwin_pal[jcBOX]);
7271 jwin_draw_frame(screen,mainbar.x,mainbar.y,mainbar.w,mainbar.h,FR_WIN);
7272
7273 FONT* oldfont = font;
7274 font = get_custom_font(CFONT_GUI);
7275
7276 //Drawmode button
7277 draw_text_button(screen,drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode],vc(1),vc(14),0,true);
7278 //Compact button
7279 draw_text_button(screen,compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact", vc(1),vc(14),0,true);
7280 //Zoom buttons
7281 zoom_in_btn_disabled = num_screens_to_draw == 1;
7282 zoom_out_btn_disabled = num_screens_to_draw == mapscreen_num_screens_to_draw_max;
7283 draw_text_button(screen,zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+", vc(1),vc(14),zoom_in_btn_disabled ? D_DISABLED : 0,true);
7284 draw_text_button(screen,zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-", vc(1),vc(14),zoom_out_btn_disabled ? D_DISABLED : 0,true);
7285
7286 font = oldfont;
7287
7288 d_nbmenu_proc(MSG_DRAW, &dialogs[0], 0);
7289
7290 ComboBrushPause=0;
7291
7292 SCRFIX();
7293 if(update)
7294 custom_vsync();
7295 is_refreshing = refreshing = false;
7296 11 }
7297
7298 12 static int minimap_tooltip_id = ttip_register_id();
7299
7300 void select_scr()
7301 {
7302 if(Map.getCurrMap()>=Map.getMapCount())
7303 return;
7304
7305 int32_t tempcb=ComboBrush;
7306 ComboBrush=0;
7307
7308 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
7309
7310 //scooby
7311 while(gui_mouse_b())
7312 {
7313 int32_t x=gui_mouse_x();
7314 int32_t y=gui_mouse_y();
7315
7316 int32_t ind = real_mini.rectind(x,y);
7317
7318 if(ind>=MAPSCRS)
7319 ind-=16;
7320
7321 if(ind > -1 && ind != Map.getCurrScr())
7322 {
7323 Map.setCurrScr(ind);
7324 }
7325
7326 custom_vsync();
7327 refresh(rALL);
7328 }
7329
7330 ComboBrush=tempcb;
7331 }
7332
7333 void clear_cpool()
7334 {
7335 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
7336 {
7337 pool_combos[i].clear();
7338 }
7339 pool_dirty = true;
7340 }
7341
7342 bool select_favorite()
7343 {
7344 int32_t tempcb=ComboBrush;
7345 ComboBrush=0;
7346 bool valid=false;
7347
7348 while(gui_mouse_b())
7349 {
7350 valid=false;
7351 int32_t x=gui_mouse_x();
7352
7353 if(x<favorites_list.x)
7354 x=favorites_list.x;
7355
7356 if(x>favorites_list.x+(favorites_list.w*favorites_list.xscale)-1)
7357 x=favorites_list.x+(favorites_list.w*favorites_list.xscale)-1;
7358
7359 int32_t y=gui_mouse_y();
7360
7361 if(y<favorites_list.y)
7362 y=favorites_list.y;
7363
7364 if(y>favorites_list.y+(favorites_list.h*favorites_list.yscale)-1)
7365 y=favorites_list.y+(favorites_list.h*favorites_list.yscale)-1;
7366
7367 int32_t tempc=(((y-favorites_list.y)/favorites_list.yscale)*FAVORITECOMBO_PER_ROW)+((x-favorites_list.x)/favorites_list.xscale) + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
7368
7369 if(tempc >= MAXFAVORITECOMBOS)
7370 {
7371 //Nothing, invalid
7372 }
7373 else
7374 {
7375 if(favorite_combos[tempc]!=-1)
7376 {
7377 switch(favorite_combo_modes[tempc])
7378 {
7379 case dm_alias:
7380 draw_mode = dm_alias;
7381 combo_apos = favorite_combos[tempc];
7382 break;
7383 case dm_cpool:
7384 draw_mode = dm_cpool;
7385 combo_pool_pos = favorite_combos[tempc];
7386 break;
7387 case dm_auto:
7388 draw_mode = dm_auto;
7389 combo_auto_pos = favorite_combos[tempc];
7390 break;
7391 default:
7392 draw_mode = dm_normal;
7393 Combo = favorite_combos[tempc];
7394 }
7395 if(AutoBrush)
7396 BrushWidth = BrushHeight = 1;
7397 valid=true;
7398 fix_drawing_mode_menu();
7399 }
7400 }
7401
7402 custom_vsync();
7403 refresh(rALL);
7404 }
7405
7406 ComboBrush=tempcb;
7407 return valid;
7408 }
7409
7410 void select_combo(int32_t clist)
7411 {
7412 current_combolist=clist;
7413 int32_t tempcb=ComboBrush;
7414 ComboBrush=0;
7415
7416 int autobrush_cx = -1, autobrush_cy = -1;
7417 int autobrush_first = First[current_combolist];
7418 auto& curlist = combolist[current_combolist];
7419 AutoBrushRevert = (key[KEY_ALT]||key[KEY_ALTGR]);
7420 while(gui_mouse_b())
7421 {
7422 int32_t x=gui_mouse_x();
7423
7424 if(x<curlist.x)
7425 x=curlist.x;
7426
7427 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7428 x=curlist.x+(curlist.w*curlist.xscale)-1;
7429
7430 int32_t y=gui_mouse_y();
7431
7432 if(y<curlist.y)
7433 y=curlist.y;
7434
7435 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7436 y=curlist.y+(curlist.h*curlist.yscale)-1;
7437
7438 int cx = ((x-curlist.x)/curlist.xscale), cy = ((y-curlist.y)/curlist.yscale);
7439 if(AutoBrush)
7440 {
7441 if(autobrush_cx < 0)
7442 {
7443 autobrush_cx = cx;
7444 autobrush_cy = cy;
7445 }
7446 BrushWidth = vbound(abs(autobrush_cx-cx)+1,1,16);
7447 BrushHeight = vbound(abs(autobrush_cy-cy)+1,1,11);
7448 cx = std::min(autobrush_cx,cx);
7449 cy = std::min(autobrush_cy,cy);
7450 }
7451 Combo=(cy*curlist.w)+cx+First[current_combolist];
7452 custom_vsync();
7453 refresh(rALL);
7454 if(AutoBrush) //Prevent any scrolling
7455 First[current_combolist] = autobrush_first;
7456 }
7457 if(key[KEY_ALT]||key[KEY_ALTGR])
7458 AutoBrushRevert = true;
7459 position_mouse_z(0);
7460 ComboBrush=tempcb;
7461 }
7462
7463 void select_comboa(int32_t clist)
7464 {
7465 current_comboalist=clist;
7466 int32_t tempcb=ComboBrush;
7467 ComboBrush=0;
7468 alias_cset_mod=0;
7469
7470 auto& curlist = comboaliaslist[current_comboalist];
7471 while(gui_mouse_b())
7472 {
7473 int32_t x=gui_mouse_x();
7474
7475 if(x<curlist.x)
7476 x=curlist.x;
7477
7478 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7479 x=curlist.x+(curlist.w*curlist.xscale)-1;
7480
7481 int32_t y=gui_mouse_y();
7482
7483 if(y<curlist.y)
7484 y=curlist.y;
7485
7486 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7487 y=curlist.y+(curlist.h*curlist.yscale)-1;
7488
7489 combo_apos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_alistpos[current_comboalist];
7490 custom_vsync();
7491 refresh(rALL);
7492 }
7493
7494 ComboBrush=tempcb;
7495 }
7496
7497 void select_combop(int32_t clist)
7498 {
7499 current_cpoollist=clist;
7500 int32_t tempcb=ComboBrush;
7501 ComboBrush=0;
7502
7503 auto& curlist = comboaliaslist[current_cpoollist];
7504 while(gui_mouse_b())
7505 {
7506 int32_t x=gui_mouse_x();
7507
7508 if(x<curlist.x) x=curlist.x;
7509
7510 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7511 x=curlist.x+(curlist.w*curlist.xscale)-1;
7512
7513 int32_t y=gui_mouse_y();
7514
7515 if(y<curlist.y) y=curlist.y;
7516
7517 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7518 y=curlist.y+(curlist.h*curlist.yscale)-1;
7519
7520 combo_pool_pos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_pool_listpos[current_cpoollist];
7521 custom_vsync();
7522 refresh(rALL);
7523 }
7524
7525 ComboBrush=tempcb;
7526 }
7527
7528 void select_autocombo(int32_t clist)
7529 {
7530 current_cautolist = clist;
7531 int32_t tempcb = ComboBrush;
7532 ComboBrush = 0;
7533
7534 auto& curlist = comboaliaslist[current_cautolist];
7535 while (gui_mouse_b())
7536 {
7537 int32_t x = gui_mouse_x();
7538
7539 if (x < curlist.x) x = curlist.x;
7540
7541 if (x > curlist.x + (curlist.w * curlist.xscale) - 1)
7542 x = curlist.x + (curlist.w * curlist.xscale) - 1;
7543
7544 int32_t y = gui_mouse_y();
7545
7546 if (y < curlist.y) y = curlist.y;
7547
7548 if (y > curlist.y + (curlist.h * curlist.yscale) - 1)
7549 y = curlist.y + (curlist.h * curlist.yscale) - 1;
7550
7551 combo_auto_pos = (((y - curlist.y) / curlist.yscale) * curlist.w) + ((x - curlist.x) / curlist.xscale) + combo_auto_listpos[current_cautolist];
7552 cauto_height = combo_autos[combo_auto_pos].getArg() + 1;
7553 custom_vsync();
7554 refresh(rALL);
7555 }
7556
7557 ComboBrush = tempcb;
7558 }
7559
7560 void update_combobrush()
7561 {
7562 clear_bitmap(brushbmp);
7563
7564 if(draw_mode==dm_alias)
7565 {
7566 //int32_t count=(combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*(comboa_lmasktotal(combo_aliases[combo_apos].layermask));
7567 for(int32_t z=0; z<=comboa_lmasktotal(combo_aliases[combo_apos].layermask); z++)
7568 {
7569 for(int32_t y=0; y<=combo_aliases[combo_apos].height; y++)
7570 {
7571 for(int32_t x=0; x<=combo_aliases[combo_apos].width; x++)
7572 {
7573 int32_t position = ((y*(combo_aliases[combo_apos].width+1))+x)+((combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*z);
7574
7575 if(combo_aliases[combo_apos].combos[position])
7576 {
7577 if(z==0)
7578 {
7579 putcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7580 }
7581 else
7582 {
7583 overcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7584 }
7585 }
7586 }
7587 }
7588 }
7589
7590 int xoff = 6, yoff = 6;
7591 if(FloatBrush) // Offset the floating pixels, so the 'x' appears centered on the combo still -Em
7592 {
7593 xoff += 2;
7594 yoff += 2;
7595 }
7596 if(alias_origin & 1) // Right-align
7597 xoff += combo_aliases[combo_apos].width*16;
7598 if(alias_origin & 2) // Bottom-align
7599 yoff += combo_aliases[combo_apos].height*16;
7600
7601 textprintf_shadowed_ex(brushbmp, get_zc_font(font_sfont), xoff, yoff, vc(15), vc(0), -1, "x");
7602 }
7603 else if(draw_mode != dm_cpool)
7604 {
7605 int32_t cid = combobrushoverride > -1 ? combobrushoverride : Combo;
7606 int32_t c = 0;
7607
7608 for(int32_t i=0; i<256; i++)
7609 {
7610 if(unsigned(cid+c) >= MAXCOMBOS) break;
7611 if(((i%COMBOS_PER_ROW)<BrushWidth)&&((i/COMBOS_PER_ROW)<BrushHeight))
7612 {
7613 put_combo(brushbmp,(i%COMBOS_PER_ROW)<<4,(i/COMBOS_PER_ROW)<<4,cid+c,CSet,Flags&(cFLAGS|cWALK),0);
7614 }
7615
7616 if(((cid+c)&3)==3)
7617 c+=48;
7618
7619 ++c;
7620
7621 if((i%COMBOS_PER_ROW)==(COMBOS_PER_ROW-1))
7622 c-=256;
7623 }
7624 }
7625 }
7626
7627 byte relational_source_grid[256]=
7628 {
7629 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7630 16, 16, 17, 17, 18, 18, 19, 19, 16, 16, 17, 17, 18, 18, 19, 19,
7631 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
7632 24, 24, 24, 24, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25,
7633 26, 27, 26, 27, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29, 28, 29,
7634 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
7635 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32,
7636 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
7637 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37,
7638 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39,
7639 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
7640 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
7641 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43,
7642 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
7643 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
7644 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46
7645 };
7646
7647 static void draw_autocombo(ComboPosition combo_pos, bool rclick, bool pressframe = false)
7648 {
7649 combo_auto &ca = combo_autos[combo_auto_pos];
7650 int screen = Map.getScreenForPosition(combo_pos);
7651 int pos = combo_pos.truncate();
7652
7653 if (ca.valid())
7654 {
7655 switch (ca.getType())
7656 {
7657 case AUTOCOMBO_BASIC:
7658 {
7659 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7660 if (rclick)
7661 ap.erase(screen, pos);
7662 else
7663 ap.execute(screen, pos);
7664 break;
7665 }
7666 case AUTOCOMBO_Z1:
7667 {
7668 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7669 if (rclick)
7670 ap.erase(screen, pos);
7671 else
7672 ap.execute(screen, pos);
7673 break;
7674 }
7675 case AUTOCOMBO_FENCE:
7676 {
7677 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7678 if (rclick)
7679 ap.erase(screen, pos);
7680 else
7681 ap.execute(screen, pos);
7682 break;
7683 }
7684 case AUTOCOMBO_Z4:
7685 {
7686 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7687 if (rclick)
7688 ap.erase(screen, pos);
7689 else
7690 ap.execute(screen, pos);
7691 break;
7692 }
7693 case AUTOCOMBO_RELATIONAL:
7694 {
7695 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7696 if (rclick)
7697 ap.erase(screen, pos);
7698 else
7699 ap.execute(screen, pos);
7700 break;
7701 }
7702 case AUTOCOMBO_DGNCARVE:
7703 {
7704 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7705 if (rclick)
7706 ap.erase(screen, pos);
7707 else
7708 ap.execute(screen, pos);
7709 break;
7710 }
7711 case AUTOCOMBO_DOR:
7712 {
7713 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7714 if (rclick)
7715 ap.erase(screen, pos);
7716 else
7717 ap.execute(screen, pos);
7718 break;
7719 }
7720 case AUTOCOMBO_TILING:
7721 {
7722 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7723 {
7724 int32_t x = (screen % 16) * 16 + (pos % 16);
7725 int32_t y = (screen / 16) * 11 + (pos / 16);
7726 byte w = (ca.getArg() & 0xF) + 1;
7727 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7728 ca.setOffsets(x % w, y % h);
7729 }
7730 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7731 if (rclick)
7732 ap.erase(screen, pos);
7733 else
7734 ap.execute(screen, pos);
7735 break;
7736 }
7737 case AUTOCOMBO_REPLACE:
7738 {
7739 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7740 if (rclick)
7741 ap.erase(screen, pos);
7742 else
7743 ap.execute(screen, pos);
7744 break;
7745 }
7746 case AUTOCOMBO_DENSEFOREST:
7747 {
7748 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7749 {
7750 int32_t x = (screen % 16) * 16 + (pos % 16);
7751 int32_t y = (screen / 16) * 11 + (pos / 16);
7752 ca.setOffsets(x % 2, y % 2);
7753 }
7754 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7755 if (rclick)
7756 ap.erase(screen, pos);
7757 else
7758 ap.execute(screen, pos);
7759 break;
7760 }
7761 case AUTOCOMBO_EXTEND:
7762 {
7763 if (CHECK_CTRL_CMD)
7764 break;
7765 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7766 if (rclick)
7767 ap.erase(screen, pos);
7768 else
7769 ap.execute(screen, pos);
7770 break;
7771 }
7772 }
7773 }
7774 else
7775 {
7776 ca.updateValid();
7777 if(!ca.valid())
7778 InfoDialog("Notice", "The autocombo you're trying to use is invalid. Reason:"
7779 + ca.getInvalidReason()).show();
7780 }
7781 }
7782
7783 static void draw_autocombo_command(ComboPosition combo_pos, int32_t cmd = 0, int32_t arg = 0)
7784 {
7785 combo_auto ca = combo_autos[combo_auto_pos];
7786 int screen = Map.getScreenForPosition(combo_pos);
7787 int pos = combo_pos.truncate();
7788
7789 if (ca.valid())
7790 {
7791 switch (ca.getType())
7792 {
7793 case AUTOCOMBO_FENCE:
7794 {
7795 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7796 ap.flip_all_connected(screen, pos, 2048);
7797 break;
7798 }
7799 case AUTOCOMBO_Z4:
7800 {
7801 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7802 switch (cmd)
7803 {
7804 case 0: // Flip
7805 ap.flip_all_connected(screen, pos, 2048);
7806 break;
7807 case 1: // Grow
7808 ap.resize_connected(screen, pos, 2048, vbound(arg, 1, 9));
7809 break;
7810 }
7811 }
7812 }
7813 }
7814 }
7815
7816 static int32_t get_autocombo_floating_cid(ComboPosition combo_pos, bool clicked)
7817 {
7818 combo_auto& ca = combo_autos[combo_auto_pos];
7819 int screen = Map.getScreenForPosition(combo_pos);
7820 int pos = combo_pos.truncate();
7821 int cid = 0;
7822
7823 if (ca.valid() && Map.isValidPosition(mouse_combo_pos))
7824 {
7825 switch (ca.getType())
7826 {
7827 case AUTOCOMBO_BASIC:
7828 {
7829 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7830 cid = ap.get_floating_cid(screen, pos);
7831 break;
7832 }
7833
7834 case AUTOCOMBO_Z1:
7835 {
7836 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7837 cid = ap.get_floating_cid(screen, pos);
7838 break;
7839 }
7840 case AUTOCOMBO_FENCE:
7841 {
7842 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7843 cid = ap.get_floating_cid(screen, pos);
7844 break;
7845 }
7846 case AUTOCOMBO_Z4:
7847 {
7848 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7849 cid = ap.get_floating_cid(screen, pos);
7850 break;
7851 }
7852 case AUTOCOMBO_RELATIONAL:
7853 {
7854 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7855 cid = ap.get_floating_cid(screen, pos);
7856 break;
7857 }
7858 case AUTOCOMBO_DGNCARVE:
7859 {
7860 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7861 cid = ap.get_floating_cid(screen, pos);
7862 break;
7863 }
7864 case AUTOCOMBO_DOR:
7865 {
7866 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, screen, pos, &ca, cauto_height);
7867 cid = ap.get_floating_cid(screen, pos);
7868 break;
7869 }
7870 case AUTOCOMBO_TILING:
7871 {
7872 std::pair<byte, byte> offs = ca.getOffsets();
7873 if (!clicked && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7874 {
7875 int32_t x = (screen % 16) * 16 + (pos % 16);
7876 int32_t y = (screen / 16) * 11 + (pos / 16);
7877 byte w = (ca.getArg() & 0xF) + 1;
7878 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7879 offs.first = (x % w);
7880 offs.second = (y % h);
7881 }
7882 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7883 cid = ap.get_floating_cid(screen, pos);
7884 break;
7885 }
7886 case AUTOCOMBO_REPLACE:
7887 {
7888 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7889 cid = ap.get_floating_cid(screen, pos);
7890 break;
7891 }
7892 case AUTOCOMBO_DENSEFOREST:
7893 {
7894 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7895 cid = ap.get_floating_cid(screen, pos);
7896 break;
7897 }
7898 case AUTOCOMBO_EXTEND:
7899 {
7900 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, screen, pos, &ca);
7901 cid = ap.get_floating_cid(screen, pos);
7902 break;
7903 }
7904 }
7905 }
7906 return cid;
7907 }
7908
7909 void change_autocombo_height(int32_t change)
7910 {
7911 bool can_change = false;
7912 if (draw_mode == dm_auto)
7913 {
7914 combo_auto ca = combo_autos[combo_auto_pos];
7915 switch (ca.getType())
7916 {
7917 case AUTOCOMBO_Z4:
7918 can_change = true;
7919 [[fallthrough]];
7920 case AUTOCOMBO_DOR:
7921 break;
7922 default:
7923 return;
7924 }
7925 }
7926 else
7927 return;
7928
7929 int32_t x = gui_mouse_x();
7930 int32_t y = gui_mouse_y();
7931 double startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
7932 double starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
7933 int32_t startxint = mapscreen_x + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7934 int32_t startyint = mapscreen_y + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7935 ComboPosition pos = get_mapscreen_mouse_combo_pos();
7936
7937 if (can_change && isinRect(x, y, startxint, startyint, int32_t(startx + (256 * mapscreen_single_scale) - 1), int32_t(starty + (176 * mapscreen_single_scale) - 1)))
7938 {
7939 Map.StartListCommand();
7940 draw_autocombo_command(pos, 1, cauto_height + change);
7941 Map.FinishListCommand();
7942 }
7943 cauto_height = vbound(cauto_height + change, 1, 9);
7944 }
7945
7946 void draw(bool justcset)
7947 {
7948 combo_pool const& pool = combo_pools[combo_pool_pos];
7949 if(draw_mode == dm_cpool && !pool.valid())
7950 return;
7951 saved=false;
7952
7953 refresh(rMAP+rSCRMAP);
7954 ComboPosition last_pos = {-1, -1};
7955
7956 Map.StartListCommand();
7957 bool pressframe = true;
7958 while(gui_mouse_b())
7959 {
7960 int32_t x=gui_mouse_x();
7961 int32_t y=gui_mouse_y();
7962 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
7963 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
7964 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
7965 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
7966 int num_combos_width = 16 * Map.getViewSize();
7967 int num_combos_height = 11 * Map.getViewSize();
7968
7969 if(isinRect(x,y,startxint,startyint,int32_t(startx+(256*mapscreen_screenunit_scale)-1),int32_t(starty+(176*mapscreen_screenunit_scale)-1)))
7970 {
7971 int32_t cxstart=(x-startx)/(16*mapscreen_single_scale);
7972 int32_t cystart=(y-starty)/(16*mapscreen_single_scale);
7973 ComboPosition combo_start = {cxstart, cystart};
7974 if (pressframe)
7975 {
7976 last_pos = combo_start;
7977 }
7978 else if (combo_start == last_pos)
7979 {
7980 custom_vsync();
7981 refresh(rALL);
7982 continue;
7983 }
7984 else if(draw_mode == dm_auto)
7985 {
7986 // TODO: support when zoomed out.
7987 if (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE || combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4)
7988 {
7989 // Don't allow moving the brush at anything but cardinal directions while in these modes
7990 bool did_diag = std::abs(combo_start.x - last_pos.x) == 1 && std::abs(combo_start.y - last_pos.y) == 1;
7991
7992 if (did_diag)
7993 {
7994 int32_t oldx = last_pos.x;
7995 int32_t oldy = last_pos.y;
7996 int32_t cx = (oldx * 16 * mapscreen_single_scale) + 8;
7997 int32_t cy = (oldy * 16 * mapscreen_single_scale) + 8;
7998 int32_t nx = x - startxint;
7999 int32_t ny = y - startyint;
8000 if (std::abs(nx - cx) < std::abs(ny - cy))
8001 {
8002 oldy = vbound(oldy + ((ny - cy) < 0 ? -1 : 1), 0, 11);
8003 }
8004 else
8005 {
8006 oldx = vbound(oldx + ((nx - cx) < 0 ? -1 : 1), 0, 15);
8007 }
8008 combo_start = {oldx, oldy};
8009 }
8010 }
8011 }
8012 last_pos = combo_start;
8013
8014 switch(draw_mode)
8015 {
8016 case dm_normal:
8017 {
8018 int32_t cc=Combo;
8019
8020 for(int32_t cy=0; cy+cystart<num_combos_height&&cy<BrushHeight; cy++)
8021 {
8022 for(int32_t cx=0; cx+cxstart<num_combos_width&&cx<BrushWidth; cx++)
8023 {
8024 auto pos = combo_start + ComboPosition{cx, cy};
8025 cc=Combo + cx + cy*4;
8026 Map.DoSetComboCommand(pos, justcset ? -1 : cc, CSet);
8027 }
8028 }
8029
8030 update_combobrush();
8031 }
8032 break;
8033 case dm_cpool:
8034 {
8035 int32_t cid = Combo;
8036 int8_t cs = CSet;
8037 pool.pick(cid,cs);
8038 Map.DoSetComboCommand(combo_start, justcset ? -1 : cid, cs);
8039
8040 update_combobrush();
8041 }
8042 break;
8043
8044 case dm_alias:
8045 {
8046 combo_alias *combo = &combo_aliases[combo_apos];
8047 if(!combo->layermask)
8048 {
8049 int32_t ox=0, oy=0;
8050
8051 switch(alias_origin)
8052 {
8053 case 0:
8054 ox=0;
8055 oy=0;
8056 break;
8057
8058 case 1:
8059 ox=(combo->width);
8060 oy=0;
8061 break;
8062
8063 case 2:
8064 ox=0;
8065 oy=(combo->height);
8066 break;
8067
8068 case 3:
8069 ox=(combo->width);
8070 oy=(combo->height);
8071 break;
8072 }
8073
8074 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8075 {
8076 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8077 {
8078 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8079 {
8080 int32_t p=(cy*(combo->width+1))+cx;
8081
8082 if(combo->combos[p])
8083 {
8084 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8085 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8086 }
8087 }
8088 }
8089 }
8090 }
8091 else
8092 {
8093 int32_t laypos = 0;
8094 int32_t ox=0, oy=0;
8095
8096 switch(alias_origin)
8097 {
8098 case 0:
8099 ox=0;
8100 oy=0;
8101 break;
8102
8103 case 1:
8104 ox=(combo->width);
8105 oy=0;
8106 break;
8107
8108 case 2:
8109 ox=0;
8110 oy=(combo->height);
8111 break;
8112
8113 case 3:
8114 ox=(combo->width);
8115 oy=(combo->height);
8116 break;
8117 }
8118
8119 for(int32_t cz=0; cz<7; cz++)
8120 {
8121 if (cz > 0 && !(combo->layermask & (1<<(cz-1))))
8122 continue;
8123
8124 if (cz > 0)
8125 laypos++;
8126
8127 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8128 {
8129 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8130 {
8131 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8132 {
8133 int32_t p=((cy*(combo->width+1))+cx)+((combo->width+1)*(combo->height+1)*laypos);
8134
8135 if (combo->combos[p])
8136 {
8137 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8138 if(cz > 0 && Map.Scr(pos)->layermap[cz - 1] == 0)
8139 continue;
8140 int prev = CurrentLayer;
8141 CurrentLayer = cz;
8142 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8143 CurrentLayer = prev;
8144 }
8145 }
8146 }
8147 }
8148 }
8149 }
8150
8151 break;
8152 }
8153
8154 case dm_auto:
8155 {
8156 draw_autocombo(combo_start, gui_mouse_b() & 2, pressframe);
8157
8158 combobrushoverride = get_autocombo_floating_cid(combo_start, true);
8159 update_combobrush();
8160 }
8161 }
8162 }
8163 pressframe = false;
8164
8165 custom_vsync();
8166 refresh(rALL);
8167 }
8168
8169 Map.FinishListCommand();
8170 if(AutoBrushRevert)
8171 {
8172 AutoBrushRevert = false;
8173 BrushWidth = 1;
8174 BrushHeight = 1;
8175 }
8176 }
8177
8178 static void replace(ComboPosition start)
8179 {
8180 int32_t cid = Combo;
8181 int8_t cs = CSet;
8182 combo_pool const& pool = combo_pools[combo_pool_pos];
8183 if(draw_mode == dm_cpool && !pool.valid())
8184 return;
8185
8186 int c = start.truncate();
8187 mapscr* scr = Map.Scr(start, CurrentLayer);
8188 if (!scr) return;
8189
8190 int num_combos_width = 16 * Map.getViewSize();
8191 int num_combos_height = 11 * Map.getViewSize();
8192 int targetcombo = scr->data[c];
8193 int targetcset = scr->cset[c];
8194
8195 saved = false;
8196 Map.StartListCommand();
8197 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
8198 {
8199 for (int x = 0; x < num_combos_width; x++)
8200 {
8201 for (int y = 0; y < num_combos_height; y++)
8202 {
8203 ComboPosition pos = {x, y};
8204 int c = pos.truncate();
8205 mapscr* scr = Map.Scr(pos, CurrentLayer);
8206 if (!scr)
8207 continue;
8208
8209 if ((scr->cset[c]) == targetcset)
8210 {
8211 if(draw_mode == dm_cpool)
8212 pool.pick(cid,cs);
8213 Map.DoSetComboCommand(pos, -1, cs);
8214 }
8215 }
8216 }
8217 }
8218 else
8219 {
8220 for (int x = 0; x < num_combos_width; x++)
8221 {
8222 for (int y = 0; y < num_combos_height; y++)
8223 {
8224 ComboPosition pos = {x, y};
8225 int c = pos.truncate();
8226 mapscr* scr = Map.Scr(pos, CurrentLayer);
8227 if (!scr)
8228 continue;
8229
8230 if(((scr->data[c])==targetcombo) &&
8231 ((scr->cset[c])==targetcset))
8232 {
8233 if(draw_mode == dm_cpool)
8234 pool.pick(cid,cs);
8235 Map.DoSetComboCommand(pos, cid, cs);
8236 }
8237 }
8238 }
8239 }
8240 Map.FinishListCommand();
8241
8242 refresh(rMAP);
8243 }
8244
8245 static void draw_block(ComboPosition start, int32_t w, int32_t h)
8246 {
8247 int32_t cid = Combo;
8248 int8_t cs = CSet;
8249 if(draw_mode == dm_cpool)
8250 {
8251 combo_pool const& pool = combo_pools[combo_pool_pos];
8252 if(!pool.pick(cid,cs)) return;
8253 }
8254
8255 mapscr* scr = Map.Scr(start, CurrentLayer);
8256 if (!scr) return;
8257
8258 saved = false;
8259 Map.StartListCommand();
8260 for (int32_t y=0; y < h && y < 11*Map.getViewSize(); y++)
8261 for (int32_t x=0; x < w && x < 16*Map.getViewSize(); x++)
8262 {
8263 Map.DoSetComboCommand(start + ComboPosition{x, y}, cid+(y*4)+x, cs);
8264 }
8265
8266 Map.FinishListCommand();
8267 refresh(rMAP+rSCRMAP);
8268 }
8269
8270 static std::vector<ComboPosition> flood_filler(ComboPosition start_pos, bool allow_diagonal, std::function<bool(ComboPosition)> check)
8271 {
8272 std::vector<ComboPosition> seen, queue;
8273
8274 queue.push_back(start_pos);
8275 while (!queue.empty())
8276 {
8277 ComboPosition pos = queue.back();
8278 queue.pop_back();
8279 seen.push_back(pos);
8280
8281 ComboPosition pos2;
8282 #define FLOOD_FILLER_CHECK(dx, dy)\
8283 pos2 = pos + ComboPosition{dx, dy};\
8284 if (std::find(seen.begin(), seen.end(), pos2) == seen.end() && check(pos2))\
8285 queue.push_back(pos2);
8286
8287 FLOOD_FILLER_CHECK(0, 1);
8288 FLOOD_FILLER_CHECK(0, -1);
8289 FLOOD_FILLER_CHECK(1, 0);
8290 FLOOD_FILLER_CHECK(-1, 0);
8291
8292 if (allow_diagonal)
8293 {
8294 FLOOD_FILLER_CHECK(1, 1);
8295 FLOOD_FILLER_CHECK(1, -1);
8296 FLOOD_FILLER_CHECK(-1, 1);
8297 FLOOD_FILLER_CHECK(-1, -1);
8298 }
8299
8300 #undef FLOOD_FILLER_CHECK
8301 }
8302
8303 return seen;
8304 }
8305
8306 static void fill(int32_t targetcombo, int32_t targetcset, ComboPosition start_pos, bool allow_diagonal, bool only_cset)
8307 {
8308 bool rclick = gui_mouse_b() & 2;
8309 bool ignored_combo = false;
8310
8311 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8312 if (!scr)
8313 return;
8314
8315 int num_combos_width = 16 * Map.getViewSize();
8316 int num_combos_height = 11 * Map.getViewSize();
8317
8318 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8319 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8320 return false;
8321
8322 mapscr* scr = Map.Scr(pos, CurrentLayer);
8323 if (!scr || !scr->is_valid())
8324 return false;
8325
8326 int cid = scr->data[pos.truncate()];
8327 int cset = scr->cset[pos.truncate()];
8328
8329 if (draw_mode == dm_auto)
8330 {
8331 combo_auto const& cauto = combo_autos[combo_auto_pos];
8332
8333 ignored_combo = cauto.isIgnoredCombo(cid);
8334 if (rclick)
8335 {
8336 if (cauto.containsCombo(targetcombo))
8337 {
8338 if (!cauto.containsCombo(cid))
8339 return false;
8340 if (cauto.getType() == AUTOCOMBO_REPLACE && ignored_combo)
8341 return false;
8342 }
8343 else
8344 return false;
8345 }
8346 else
8347 {
8348 if (cid != targetcombo && !ignored_combo)
8349 return false;
8350 if (cauto.getType() == AUTOCOMBO_REPLACE && !ignored_combo)
8351 return false;
8352 }
8353
8354 if (cset != targetcset && !ignored_combo)
8355 return false;
8356 }
8357 else
8358 {
8359 if(!only_cset)
8360 {
8361 if (cid != targetcombo)
8362 return false;
8363 }
8364
8365 if (cset != targetcset)
8366 return false;
8367 }
8368
8369 return true;
8370 });
8371
8372 for (auto& pos : combo_positions)
8373 {
8374 int32_t cid = Combo;
8375 int8_t cs = CSet;
8376
8377 if (draw_mode == dm_cpool)
8378 {
8379 combo_pool const& pool = combo_pools[combo_pool_pos];
8380 if (!pool.pick(cid, cs)) continue;
8381 }
8382 else if (draw_mode == dm_auto)
8383 {
8384 combo_auto const& cauto = combo_autos[combo_auto_pos];
8385 if (!cauto.valid())
8386 continue;
8387 if (!rclick && (cauto.containsCombo(targetcombo) && !ignored_combo))
8388 continue;
8389 if (rclick && cauto.getEraseCombo() == targetcombo)
8390 continue;
8391 }
8392
8393 if (draw_mode == dm_auto)
8394 draw_autocombo(pos, rclick);
8395 else
8396 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8397 }
8398 }
8399
8400 static void fill_flag(int32_t targetflag, ComboPosition start_pos, bool allow_diagonal)
8401 {
8402 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8403 if (!scr)
8404 return;
8405
8406 int num_combos_width = 16 * Map.getViewSize();
8407 int num_combos_height = 11 * Map.getViewSize();
8408
8409 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8410 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8411 return false;
8412
8413 mapscr* scr = Map.Scr(pos, CurrentLayer);
8414 if (!scr || !scr->is_valid())
8415 return false;
8416
8417 if (scr->sflag[pos.truncate()] != targetflag)
8418 return false;
8419
8420 return true;
8421 });
8422
8423 for (auto& pos : combo_positions)
8424 Map.DoSetFlagCommand(pos, Flag);
8425 }
8426
8427 static void fill2(int32_t targetcombo, int32_t targetcset, ComboPosition pos, int32_t dir, int32_t diagonal, bool only_cset)
8428 {
8429 mapscr* scr = Map.Scr(pos, CurrentLayer);
8430 if (!scr || !scr->is_valid())
8431 return;
8432
8433 int cid = scr->data[pos.truncate()];
8434 int cset = scr->cset[pos.truncate()];
8435
8436 if (!only_cset)
8437 {
8438 if (cid == targetcombo)
8439 return;
8440 }
8441
8442 if (cset == targetcset)
8443 return;
8444
8445 cid = Combo;
8446 int8_t cs = CSet;
8447 if(draw_mode == dm_cpool)
8448 {
8449 combo_pool const& pool = combo_pools[combo_pool_pos];
8450 if(!pool.pick(cid,cs)) return;
8451 }
8452
8453 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8454
8455 int num_combos_width = 16 * Map.getViewSize();
8456 int num_combos_height = 11 * Map.getViewSize();
8457
8458 if (pos.y > 0 && dir != down)
8459 fill2(targetcombo, targetcset, pos + ComboPosition{0, -1}, up, diagonal, only_cset);
8460 if (pos.y < num_combos_height-1 && dir != up)
8461 fill2(targetcombo, targetcset, pos + ComboPosition{0, 1}, down, diagonal, only_cset);
8462 if (pos.x > 0 && dir != right)
8463 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 0}, left, diagonal, only_cset);
8464 if (pos.x < num_combos_width-1 && dir != left)
8465 fill2(targetcombo, targetcset, pos + ComboPosition{1, 0}, right, diagonal, only_cset);
8466
8467 if (diagonal == 1)
8468 {
8469 if (pos.y > 0 && pos.x > 0 && dir != r_down)
8470 fill2(targetcombo, targetcset, pos + ComboPosition{-1, -1}, l_up, diagonal, only_cset);
8471 if (pos.y < num_combos_height-1 && pos.x < num_combos_width-1 && dir != l_up)
8472 fill2(targetcombo, targetcset, pos + ComboPosition{1, 1}, r_down, diagonal, only_cset);
8473 if (pos.x > 0 && pos.y < num_combos_height-1 && dir != r_up)
8474 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 1}, l_down, diagonal, only_cset);
8475 if (pos.x < num_combos_width-1 && pos.y > 0 && dir != l_down)
8476 fill2(targetcombo, targetcset, pos + ComboPosition{1, -1}, r_up, diagonal, only_cset);
8477 }
8478 }
8479
8480
8481 enum SnapMode
8482 {
8483 SNAP_NONE, SNAP_HALF, SNAP_WHOLE
8484 };
8485 static void snap_xy(int& x, int& y, SnapMode mode, roundType rounding, optional<int> max_x = nullopt, optional<int> max_y = nullopt)
8486 {
8487 if(mode == SNAP_NONE)
8488 {
8489 if(max_x) x = vbound(x,*max_x,0);
8490 if(max_y) y = vbound(y,*max_y,0);
8491 return;
8492 }
8493 int xoff = 0, yoff = 0;
8494 switch(rounding)
8495 {
8496 case ROUND_TO_0:
8497 rounding = ROUND_DOWN;
8498 break;
8499 case ROUND_AWAY_0:
8500 rounding = ROUND_UP;
8501 break;
8502 }
8503 int r = 0;
8504 switch(mode)
8505 {
8506 case SNAP_HALF:
8507 r = 8;
8508 break;
8509 case SNAP_WHOLE:
8510 r = 16;
8511 break;
8512 }
8513 assert(r > 0);
8514 // r must be a power of 2, for bitwise reasons
8515 switch(rounding)
8516 {
8517 case ROUND_DOWN:
8518 break;
8519 case ROUND_UP:
8520 xoff = ((x & (r-1)) ? r : 0);
8521 yoff = ((y & (r-1)) ? r : 0);
8522 break;
8523 case ROUND_NEAREST:
8524 xoff = ((x & (r-1)) >= (r/2) ? r : 0);
8525 yoff = ((y & (r-1)) >= (r/2) ? r : 0);
8526 break;
8527 }
8528 x = (x & ~(r-1)) + xoff;
8529 y = (y & ~(r-1)) + yoff;
8530 if(max_x && x >= *max_x) x = *max_x-r;
8531 else if(max_x && x < 0) x = 0;
8532 if(max_y && y >= *max_y) y = *max_y-r;
8533 else if(max_y && y < 0) y = 0;
8534 }
8535
8536 static void doxypos(byte &px2, byte &py2, int32_t color, SnapMode snap_mode,
8537 SnapMode shift_mode, bool immediately, int32_t cursoroffx,
8538 int32_t cursoroffy, int32_t iconw, int32_t iconh)
8539 {
8540 int32_t tempcb=ComboBrush;
8541 ComboBrush=0;
8542 MouseSprite::set(ZQM_POINT_BOX);
8543
8544 int viz_off_x = (active_visible_screen ? active_visible_screen->dx * 256 : 0);
8545 int viz_off_y = (active_visible_screen ? active_visible_screen->dy * 176 : 0);
8546
8547 int32_t oldpx=px2, oldpy=py2;
8548 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8549 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8550 showxypos_x=px2 + viz_off_x;
8551 showxypos_y=py2 + viz_off_y;
8552 showxypos_w=iconw;
8553 showxypos_h=iconh;
8554 showxypos_color=vc(color);
8555 showxypos_icon=!showxypos_dummy;
8556 bool canedit=false;
8557 bool done=false;
8558
8559 clear_tooltip();
8560
8561 while(!done && (!(gui_mouse_b()&2) || immediately))
8562 {
8563 if(!gui_mouse_b() || immediately)
8564 {
8565 canedit=true;
8566 }
8567
8568 // TODO: would be nice if these bounds were based on the individual screen.
8569 if(canedit && gui_mouse_b()==1 && isinRect(gui_mouse_x(),gui_mouse_y(),startxint,startyint,(startxint+(256*mapscreen_screenunit_scale)-1),(startyint+(176*mapscreen_screenunit_scale)-1)))
8570 {
8571 set_mouse_range(startxint,startyint,int32_t(startxint+(256*mapscreen_screenunit_scale)-1),int32_t(startyint+(176*mapscreen_screenunit_scale)-1));
8572
8573 double offx = 0, offy = 0;
8574 roundType rounding = ROUND_DOWN;
8575 if(DragCenterOfSquares)
8576 {
8577 offx -= iconw*mapscreen_single_scale/2;
8578 offy -= iconh*mapscreen_single_scale/2;
8579 rounding = ROUND_NEAREST;
8580 }
8581 int32_t x, y;
8582 do
8583 {
8584 x=int32_t((gui_mouse_x()-startxint+offx)/mapscreen_single_scale)-cursoroffx;
8585 y=int32_t((gui_mouse_y()-startyint+offy)/mapscreen_single_scale)-cursoroffy;
8586 showxypos_cursor_icon=true;
8587 showxypos_cursor_color = showxypos_color;
8588 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8589 showxypos_cursor_x = x-viz_off_x;
8590 showxypos_cursor_y = y-viz_off_y;
8591 snap_xy(showxypos_cursor_x, showxypos_cursor_y, _mode, rounding, 256, 176);
8592 showxypos_cursor_x += viz_off_x;
8593 showxypos_cursor_y += viz_off_y;
8594 custom_vsync();
8595 refresh(rALL | rNOCURSOR);
8596 int32_t xpos[2], ypos[2];
8597 int32_t x1,y1,x2,y2;
8598
8599 char b1[200] = {0};
8600 char b2[200] = {0};
8601 if(showxypos_dummy)
8602 strcpy(b1, "DUMMY MEASURING");
8603 else sprintf(b1, "%d %d",oldpx,oldpy);
8604 sprintf(b2, "%d %d (%d %d)",x-viz_off_x,y-viz_off_y,showxypos_cursor_x-viz_off_x,showxypos_cursor_y-viz_off_y);
8605
8606 int len[2] = {text_length(font,b1),text_length(font,b2)};
8607
8608 if(is_compact)
8609 {
8610 xpos[0] = 4;
8611 ypos[0] = layer_panel.y - 21;
8612 xpos[1] = xpos[0];
8613 ypos[1] = ypos[0]+10;
8614 }
8615 else
8616 {
8617 xpos[0] = 450;
8618 ypos[0] = 405;
8619 xpos[1] = xpos[0];
8620 ypos[1] = ypos[0]+10;
8621 }
8622
8623 x1 = xpos[0];
8624 y1 = ypos[0];
8625 x2 = xpos[0];
8626 y2 = ypos[0];
8627 for(auto q = 0; q < 2; ++q)
8628 {
8629 if(xpos[q] < x1)
8630 x1 = xpos[q];
8631 if(ypos[q] < y1)
8632 y1 = ypos[q];
8633 if(ypos[q] > y2)
8634 y2 = ypos[q];
8635 if(xpos[q] + len[q] > x2)
8636 x2 = xpos[q] + len[q];
8637 }
8638 x1 -= 4;
8639 y1 -= 2;
8640 y2 += text_height(font)+2;
8641
8642 auto minx = zc_min(xpos[0],xpos[1]);
8643 auto miny = zc_min(ypos[0],ypos[1]);
8644 rectfill(screen,x1,y1,x2,y2,vc(0));
8645 textprintf_ex(screen,font,xpos[0],ypos[0],vc(15),vc(0),"%s",b1);
8646 textprintf_ex(screen,font,xpos[1],ypos[1],vc(15),vc(0),"%s",b2);
8647 update_hw_screen();
8648 }
8649 while(gui_mouse_b()==1);
8650
8651 if(gui_mouse_b()==0)
8652 {
8653 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8654 int x2 = vbound(x-viz_off_x,0,255);
8655 int y2 = vbound(y-viz_off_y,0,175);
8656 snap_xy(x2, y2, _mode, rounding, 256, 176);
8657 px2=byte(x2);
8658 py2=byte(y2);
8659 }
8660
8661 set_mouse_range(0,0,zq_screen_w-1,zq_screen_h-1);
8662 done=true;
8663 }
8664
8665 if(keypressed())
8666 {
8667 switch(readkey()>>8)
8668 {
8669 case KEY_ESC:
8670 case KEY_ENTER:
8671 goto finished;
8672 }
8673 }
8674
8675 custom_vsync();
8676 refresh(rALL | rNOCURSOR);
8677 }
8678
8679 finished:
8680 MouseSprite::set(ZQM_NORMAL);
8681 refresh(rMAP+rMENU);
8682
8683 while(gui_mouse_b())
8684 {
8685 /* do nothing */
8686 rest(1);
8687 }
8688
8689 showxypos_x=-1000;
8690 showxypos_y=-1000;
8691 showxypos_color=-1000;
8692 showxypos_ffc=-1000;
8693 showxypos_icon=false;
8694 showxypos_cursor_x=-1000;
8695 showxypos_cursor_y=-1000;
8696 showxypos_cursor_icon=false;
8697 showxypos_cursor_color=-1000;
8698 showxypos_dummy=false;
8699
8700 if(px2!=oldpx||py2!=oldpy)
8701 {
8702 saved=false;
8703 }
8704
8705 ComboBrush=tempcb;
8706 }
8707 static void doxypos(byte &px2,byte &py2,int32_t color,SnapMode snap_mode, optional<SnapMode> shift_mode = nullopt)
8708 {
8709 doxypos(px2,py2,color,snap_mode,shift_mode ? *shift_mode : snap_mode,false,0,0,16,16);
8710 }
8711
8712 bool placing_flags = false;
8713 void doflags()
8714 {
8715 placing_flags = true;
8716 int of=Flags;
8717 Flags=cFLAGS;
8718 refresh(rMAP | rNOCURSOR);
8719
8720 bool canedit=false;
8721 bool didShift = false;
8722 int tFlag = Flag;
8723 while(!(gui_mouse_b()&2) && !handle_close_btn_quit())
8724 {
8725 int x=gui_mouse_x();
8726 int y=gui_mouse_y();
8727 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8728 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8729 int startxint=mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
8730 int startyint=mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
8731 int cx=(x-startxint)/int(16*mapscreen_single_scale);
8732 int cy=(y-startyint)/int(16*mapscreen_single_scale);
8733 ComboPosition combo_pos = {cx, cy};
8734 int c = combo_pos.truncate();
8735
8736 if(!gui_mouse_b())
8737 canedit=true;
8738 bool shift = key[KEY_LSHIFT] || key[KEY_RSHIFT];
8739
8740 if(canedit && gui_mouse_b()==1 && isinRect(x,y,startxint,startyint,int(startx+(256*mapscreen_screenunit_scale)-1),int(starty+(176*mapscreen_screenunit_scale)-1)))
8741 {
8742 mapscr* cur_scr = Map.Scr(combo_pos, CurrentLayer);
8743 if (!cur_scr) continue;
8744
8745 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
8746
8747 if(key[KEY_ALT]||key[KEY_ALTGR])
8748 Flag = cur_scr->sflag[c];
8749 else
8750 {
8751 saved=false;
8752 int tflag = Flag;
8753 if(shift)
8754 Flag = mfNONE;
8755 if(CurrentLayer!=0)
8756 {
8757 // Notify if they are using a flag that doesn't work on this layer.
8758 if(!skipLayerWarning && ((Flag >= mfTRAP_H && Flag < mfPUSHD) || (Flag == mfFAIRY) || (Flag == mfMAGICFAIRY)
8759 || (Flag == mfALLFAIRY) || (Flag == mfRAFT) || (Flag == mfRAFT_BRANCH)
8760 || (Flag == mfDIVE_ITEM) || (Flag == mfARMOS_SECRET) || (Flag == mfNOENEMY)
8761 || (Flag == mfZELDA)))
8762 {
8763 InfoDialog("Notice","You are currently working on layer "
8764 +to_string(CurrentLayer)
8765 +". This combo flag does not function on layers above '0'.").show();
8766 }
8767 if(!skipLayerWarning && CurrentLayer > 2 &&
8768 ((Flag == mfBLOCKHOLE) || (Flag >= mfPUSHD && Flag < mfNOBLOCKS)
8769 || (Flag == mfPUSHUD) || (Flag == mfPUSH4)))
8770 {
8771 InfoDialog("Notice","You are currently working on layer "
8772 +to_string(CurrentLayer)
8773 +". This combo flag does not function on layers above '2'.").show();
8774 }
8775 }
8776 if(CHECK_CTRL_CMD)
8777 {
8778 switch(fill_type)
8779 {
8780 case 0:
8781 flood_flag();
8782 break;
8783
8784 case 1:
8785 case 3:
8786 fill_4_flag();
8787 break;
8788
8789 case 2:
8790 case 4:
8791 fill_8_flag();
8792 break;
8793 }
8794 }
8795 else
8796 {
8797 Map.DoSetFlagCommand(combo_pos, Flag);
8798 }
8799 Flag = tflag;
8800 }
8801 }
8802
8803 if(mouse_z)
8804 {
8805 for(int i=0; i<abs(mouse_z); ++i)
8806 {
8807 if(mouse_z>0)
8808 onIncreaseFlag();
8809 else
8810 onDecreaseFlag();
8811 }
8812
8813 position_mouse_z(0);
8814 }
8815
8816 if(keypressed())
8817 {
8818 int k = readkey();
8819 switch(k>>8)
8820 {
8821 case KEY_ESC:
8822 case KEY_ENTER:
8823 goto finished;
8824 }
8825 object_message(dialogs+1, MSG_XCHAR, k);
8826 Flags=cFLAGS;
8827 }
8828
8829 MouseSprite::set(ZQM_FLAG_0+(shift?0:Flag%16));
8830
8831 refresh(rALL | rCLEAR | rNOCURSOR);
8832 custom_vsync();
8833 }
8834
8835 finished:
8836 Flags=of;
8837 placing_flags = false;
8838 MouseSprite::set(ZQM_NORMAL);
8839 refresh(rMAP+rMENU);
8840
8841 while(gui_mouse_b())
8842 {
8843 /* do nothing */
8844 rest(1);
8845 }
8846 }
8847
8848 // Drag FFCs around
8849 static void moveffc(int i, int cx, int cy)
8850 {
8851 mapscr* scr = active_visible_screen->scr;
8852 int screen = active_visible_screen->screen;
8853
8854 int32_t ffx = vbound(scr->ffcs[i].x.getFloor(),0,240);
8855 int32_t ffy = vbound(scr->ffcs[i].y.getFloor(),0,160);
8856 int32_t offx = ffx, offy = ffy;
8857 showxypos_ffc = i;
8858 doxypos((byte&)ffx,(byte&)ffy,15,SNAP_HALF,SNAP_NONE,true,0,0,(scr->ffTileWidth(i)*16),(scr->ffTileHeight(i)*16));
8859 if(ffx > 240) ffx = 240;
8860 if(ffy > 160) ffy = 160;
8861 if((ffx != offx) || (ffy != offy))
8862 {
8863 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
8864 set_ffc_data.x = ffx;
8865 set_ffc_data.y = ffy;
8866 Map.DoSetFFCCommand(Map.getCurrMap(), screen, i, set_ffc_data);
8867 saved = false;
8868 }
8869 }
8870
8871 void set_brush_width(int32_t width);
8872 void set_brush_height(int32_t height);
8873
8874 int32_t set_brush_width_1()
8875 {
8876 set_brush_width(1);
8877 return D_O_K;
8878 }
8879 int32_t set_brush_width_2()
8880 {
8881 set_brush_width(2);
8882 return D_O_K;
8883 }
8884 int32_t set_brush_width_3()
8885 {
8886 set_brush_width(3);
8887 return D_O_K;
8888 }
8889 int32_t set_brush_width_4()
8890 {
8891 set_brush_width(4);
8892 return D_O_K;
8893 }
8894 int32_t set_brush_width_5()
8895 {
8896 set_brush_width(5);
8897 return D_O_K;
8898 }
8899 int32_t set_brush_width_6()
8900 {
8901 set_brush_width(6);
8902 return D_O_K;
8903 }
8904 int32_t set_brush_width_7()
8905 {
8906 set_brush_width(7);
8907 return D_O_K;
8908 }
8909 int32_t set_brush_width_8()
8910 {
8911 set_brush_width(8);
8912 return D_O_K;
8913 }
8914 int32_t set_brush_width_9()
8915 {
8916 set_brush_width(9);
8917 return D_O_K;
8918 }
8919 int32_t set_brush_width_10()
8920 {
8921 set_brush_width(10);
8922 return D_O_K;
8923 }
8924 int32_t set_brush_width_11()
8925 {
8926 set_brush_width(11);
8927 return D_O_K;
8928 }
8929 int32_t set_brush_width_12()
8930 {
8931 set_brush_width(12);
8932 return D_O_K;
8933 }
8934 int32_t set_brush_width_13()
8935 {
8936 set_brush_width(13);
8937 return D_O_K;
8938 }
8939 int32_t set_brush_width_14()
8940 {
8941 set_brush_width(14);
8942 return D_O_K;
8943 }
8944 int32_t set_brush_width_15()
8945 {
8946 set_brush_width(15);
8947 return D_O_K;
8948 }
8949 int32_t set_brush_width_16()
8950 {
8951 set_brush_width(16);
8952 return D_O_K;
8953 }
8954
8955 int32_t set_brush_height_1()
8956 {
8957 set_brush_height(1);
8958 return D_O_K;
8959 }
8960 int32_t set_brush_height_2()
8961 {
8962 set_brush_height(2);
8963 return D_O_K;
8964 }
8965 int32_t set_brush_height_3()
8966 {
8967 set_brush_height(3);
8968 return D_O_K;
8969 }
8970 int32_t set_brush_height_4()
8971 {
8972 set_brush_height(4);
8973 return D_O_K;
8974 }
8975 int32_t set_brush_height_5()
8976 {
8977 set_brush_height(5);
8978 return D_O_K;
8979 }
8980 int32_t set_brush_height_6()
8981 {
8982 set_brush_height(6);
8983 return D_O_K;
8984 }
8985 int32_t set_brush_height_7()
8986 {
8987 set_brush_height(7);
8988 return D_O_K;
8989 }
8990 int32_t set_brush_height_8()
8991 {
8992 set_brush_height(8);
8993 return D_O_K;
8994 }
8995 int32_t set_brush_height_9()
8996 {
8997 set_brush_height(9);
8998 return D_O_K;
8999 }
9000 int32_t set_brush_height_10()
9001 {
9002 set_brush_height(10);
9003 return D_O_K;
9004 }
9005 int32_t set_brush_height_11()
9006 {
9007 set_brush_height(11);
9008 return D_O_K;
9009 }
9010
9011
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_width_menu
9012 204 {
9013
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_width_1 },
9014
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_width_2 },
9015
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_width_3 },
9016
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_width_4 },
9017
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_width_5 },
9018
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_width_6 },
9019
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_width_7 },
9020
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_width_8 },
9021
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_width_9 },
9022
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_width_10 },
9023
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_width_11 },
9024
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "12", set_brush_width_12 },
9025
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "13", set_brush_width_13 },
9026
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "14", set_brush_width_14 },
9027
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "15", set_brush_width_15 },
9028
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "16", set_brush_width_16 },
9029 };
9030
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_height_menu
9031 144 {
9032
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1", set_brush_height_1 },
9033
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2", set_brush_height_2 },
9034
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3", set_brush_height_3 },
9035
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4", set_brush_height_4 },
9036
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "5", set_brush_height_5 },
9037
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "6", set_brush_height_6 },
9038
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "7", set_brush_height_7 },
9039
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "8", set_brush_height_8 },
9040
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "9", set_brush_height_9 },
9041
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "10", set_brush_height_10 },
9042
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "11", set_brush_height_11 },
9043 };
9044
9045 int toggle_autobrush();
9046 int toggle_combobrush();
9047 int toggle_floatbrush();
9048 enum
9049 {
9050 MENUID_BRUSH_AUTOBRUSH,
9051 MENUID_BRUSH_WIDTH,
9052 MENUID_BRUSH_HEIGHT,
9053 MENUID_BRUSH_COMBOBRUSH,
9054 MENUID_BRUSH_FLOATBRUSH,
9055 };
9056
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu brush_menu
9057 72 {
9058
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "AutoBrush", toggle_autobrush, MENUID_BRUSH_AUTOBRUSH },
9059
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Width ", &brush_width_menu, MENUID_BRUSH_WIDTH },
9060
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Brush Height ", &brush_height_menu, MENUID_BRUSH_HEIGHT },
9061
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "ComboBrush", toggle_combobrush, MENUID_BRUSH_COMBOBRUSH },
9062
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "FloatBrush", toggle_floatbrush, MENUID_BRUSH_FLOATBRUSH },
9063 };
9064 int toggle_autobrush()
9065 {
9066 AutoBrush = AutoBrush ? 0 : 1;
9067 BrushWidth = BrushHeight = 1;
9068 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9069 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9070 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9071 zc_set_config("zquest","autobrush",AutoBrush);
9072 return D_O_K;
9073 }
9074 int toggle_combobrush()
9075 {
9076 ComboBrush = ComboBrush ? 0 : 1;
9077 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9078 zc_set_config("zquest","combo_brush",ComboBrush);
9079 return D_O_K;
9080 }
9081 int toggle_floatbrush()
9082 {
9083 FloatBrush = FloatBrush ? 0 : 1;
9084 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9085 zc_set_config("zquest","float_brush",FloatBrush);
9086 return D_O_K;
9087 }
9088
9089 int32_t set_flood();
9090 int32_t set_fill_4();
9091 int32_t set_fill_8();
9092 int32_t set_fill2_4();
9093 int32_t set_fill2_8();
9094
9095 // Sets every combo.
9096 void flood()
9097 {
9098 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9099 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9100 if (!scr || !scr->is_valid())
9101 return;
9102
9103 saved=false;
9104
9105 bool include_combos = !(key[KEY_LSHIFT]||key[KEY_RSHIFT]);
9106
9107 int num_combos_width = 16 * Map.getViewSize();
9108 int num_combos_height = 11 * Map.getViewSize();
9109
9110 Map.StartListCommand();
9111 for (int x = 0; x < num_combos_width; x++)
9112 {
9113 for (int y = 0; y < num_combos_height; y++)
9114 {
9115 ComboPosition pos = {x, y};
9116 mapscr* scr = Map.Scr(pos, CurrentLayer);
9117 if (!scr || !scr->is_valid())
9118 continue;
9119
9120 if (draw_mode == dm_auto)
9121 draw_autocombo(pos, gui_mouse_b() & 2);
9122 else
9123 Map.DoSetComboCommand(pos, include_combos ? Combo : -1, CSet);
9124 }
9125 }
9126 Map.FinishListCommand();
9127
9128 refresh(rMAP+rSCRMAP);
9129 }
9130 void flood_flag()
9131 {
9132 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9133 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9134 if (!scr || !scr->is_valid())
9135 return;
9136
9137 saved=false;
9138
9139 int num_combos_width = 16 * Map.getViewSize();
9140 int num_combos_height = 11 * Map.getViewSize();
9141
9142 Map.StartListCommand();
9143 for (int x = 0; x < num_combos_width; x++)
9144 {
9145 for (int y = 0; y < num_combos_height; y++)
9146 {
9147 ComboPosition pos = {x, y};
9148 mapscr* scr = Map.Scr(pos, CurrentLayer);
9149 if (!scr || !scr->is_valid())
9150 continue;
9151
9152 Map.DoSetFlagCommand(pos, Flag);
9153 }
9154 }
9155 Map.FinishListCommand();
9156
9157 refresh(rMAP+rSCRMAP);
9158 }
9159
9160 void fill_4()
9161 {
9162 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9163 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9164 if (!scr)
9165 return;
9166
9167 int c = pos.truncate();
9168 if (draw_mode == dm_cpool || draw_mode == dm_auto
9169 || (scr->cset[c]!=CSet || (scr->data[c]!=Combo && !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9170 {
9171 saved=false;
9172
9173 Map.StartListCommand();
9174 if (draw_mode == dm_auto && (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE ||
9175 combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4))
9176 {
9177 draw_autocombo_command(pos);
9178 }
9179 else
9180 {
9181 bool allow_diagonal = false;
9182 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT] || key[KEY_RSHIFT]));
9183 }
9184 Map.FinishListCommand();
9185 refresh(rMAP+rSCRMAP);
9186 }
9187 }
9188 void fill_4_flag()
9189 {
9190 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9191 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9192 if (!scr)
9193 return;
9194
9195 int flag = scr->sflag[pos.truncate()];
9196 if (flag != Flag)
9197 {
9198 saved=false;
9199
9200 Map.StartListCommand();
9201 bool allow_diagonal = false;
9202 fill_flag(flag, pos, allow_diagonal);
9203 Map.FinishListCommand();
9204 refresh(rMAP+rSCRMAP);
9205 }
9206 }
9207 void fill_8()
9208 {
9209 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9210 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9211 if (!scr)
9212 return;
9213
9214 int c = pos.truncate();
9215 if (draw_mode == dm_cpool || draw_mode == dm_auto
9216 || (scr->cset[c] != CSet ||
9217 (scr->data[c] != Combo &&
9218 !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9219 {
9220 saved=false;
9221
9222 Map.StartListCommand();
9223 bool allow_diagonal = true;
9224 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9225 Map.FinishListCommand();
9226
9227 refresh(rMAP+rSCRMAP);
9228 }
9229 }
9230 void fill_8_flag()
9231 {
9232 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9233 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9234 if (!scr)
9235 return;
9236
9237 int flag = scr->sflag[pos.truncate()];
9238 if (flag != Flag)
9239 {
9240 saved=false;
9241
9242 Map.StartListCommand();
9243 bool allow_diagonal = true;
9244 fill_flag(flag, pos, allow_diagonal);
9245 Map.FinishListCommand();
9246 refresh(rMAP+rSCRMAP);
9247 }
9248 }
9249
9250 void fill2_4()
9251 {
9252 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9253 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9254 if (!scr)
9255 return;
9256
9257 saved=false;
9258
9259 Map.StartListCommand();
9260 fill2(Combo, CSet, pos, 255, 0, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9261 Map.FinishListCommand();
9262 refresh(rMAP+rSCRMAP);
9263 }
9264
9265 void fill2_8()
9266 {
9267 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9268 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9269 if (!scr)
9270 return;
9271
9272 saved=false;
9273
9274 Map.StartListCommand();
9275 fill2(Combo, CSet, pos, 255, 1, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9276 Map.FinishListCommand();
9277
9278 refresh(rMAP+rSCRMAP);
9279 }
9280
9281
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu fill_menu
9282 72 {
9283
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Flood", set_flood, 0 },
9284
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (4-way)", set_fill_4, 1 },
9285
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill (8-way)", set_fill_8, 2 },
9286
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (4-way)", set_fill2_4, 3 },
9287
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Fill2 (8-way)", set_fill2_8, 4 },
9288 };
9289 void set_filltype(int ty)
9290 {
9291 fill_type = ty;
9292 fill_menu.select_only_uid(ty);
9293 }
9294
9295 int32_t set_flood()
9296 {
9297 set_filltype(0);
9298 return D_O_K;
9299 }
9300
9301 int32_t set_fill_4()
9302 {
9303 set_filltype(1);
9304 return D_O_K;
9305 }
9306
9307 int32_t set_fill_8()
9308 {
9309 set_filltype(2);
9310 return D_O_K;
9311 }
9312
9313 int32_t set_fill2_4()
9314 {
9315 set_filltype(3);
9316 return D_O_K;
9317 }
9318
9319 int32_t set_fill2_8()
9320 {
9321 set_filltype(4);
9322 return D_O_K;
9323 }
9324
9325 int32_t draw_block_1_2()
9326 {
9327 draw_block(mouse_combo_pos,1,2);
9328 return D_O_K;
9329 }
9330
9331 int32_t draw_block_2_1()
9332 {
9333 draw_block(mouse_combo_pos,2,1);
9334 return D_O_K;
9335 }
9336
9337 int32_t draw_block_2_2()
9338 {
9339 draw_block(mouse_combo_pos,2,2);
9340 return D_O_K;
9341 }
9342
9343 int32_t draw_block_2_3()
9344 {
9345 draw_block(mouse_combo_pos,2,3);
9346 return D_O_K;
9347 }
9348
9349 int32_t draw_block_3_2()
9350 {
9351 draw_block(mouse_combo_pos,3,2);
9352 return D_O_K;
9353 }
9354
9355 int32_t draw_block_3_3()
9356 {
9357 draw_block(mouse_combo_pos,3,3);
9358 return D_O_K;
9359 }
9360
9361 int32_t draw_block_4_2()
9362 {
9363 draw_block(mouse_combo_pos,4,2);
9364 return D_O_K;
9365 }
9366
9367 int32_t draw_block_4_4()
9368 {
9369 draw_block(mouse_combo_pos,4,4);
9370 return D_O_K;
9371 }
9372
9373
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu draw_block_menu
9374 108 {
9375
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "1x2", draw_block_1_2 },
9376
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x1", draw_block_2_1 },
9377
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x2", draw_block_2_2 },
9378
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "2x3", draw_block_2_3 },
9379
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x2", draw_block_3_2 },
9380
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "3x3", draw_block_3_3 },
9381
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x2", draw_block_4_2 },
9382
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "4x4", draw_block_4_4 },
9383 };
9384
9385
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu paste_screen_menu
9386 60 {
9387
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste", onPaste },
9388
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All", onPasteAll },
9389
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste to All", onPasteToAll },
9390
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste All to All", onPasteAllToAll },
9391 };
9392
9393 int32_t scrollto_cmb(int32_t cid)
9394 {
9395 auto& sqr = combolist[current_combolist];
9396 int32_t res = vbound(cid-(sqr.w*sqr.h/2),0,MAXCOMBOS-(sqr.w*sqr.h));
9397 res -= res%sqr.w;
9398 return res;
9399 }
9400 int32_t scrollto_alias(int32_t alid)
9401 {
9402 auto& sqr = comboaliaslist[current_comboalist];
9403 int32_t res = vbound(alid-(sqr.w*sqr.h/2),0,MAXCOMBOALIASES-(sqr.w*sqr.h));
9404 res -= res%sqr.w;
9405 return res;
9406 }
9407
9408 int32_t scrollto_cpool(int32_t cpid)
9409 {
9410 auto& sqr = comboaliaslist[current_cpoollist];
9411 int32_t res = vbound(cpid-(sqr.w*sqr.h/2),0,MAXCOMBOPOOLS-(sqr.w*sqr.h));
9412 res -= res%sqr.w;
9413 return res;
9414 }
9415
9416 int32_t scrollto_cauto(int32_t caid)
9417 {
9418 auto& sqr = comboaliaslist[current_cautolist];
9419 int32_t res = vbound(caid - (sqr.w * sqr.h / 2), 0, MAXCOMBOPOOLS - (sqr.w * sqr.h));
9420 res -= res % sqr.w;
9421 return res;
9422 }
9423
9424 void add_favorite_combo_block(int32_t favind, int32_t cid, bool force)
9425 {
9426 int32_t w = vbound(BrushWidth, 1, 4);
9427 int32_t h = vbound(BrushHeight, 1, 7);
9428 for (int32_t xi = 0; xi < w; ++xi)
9429 {
9430 for (int32_t yi = 0; yi < h; ++yi)
9431 {
9432 int32_t cx = cid % 4;
9433 int32_t cy = cid / 4;
9434 int32_t cc = (cy + yi) * 4 + cx + xi;
9435 int32_t fx = favind % FAVORITECOMBO_PER_ROW;
9436 int32_t fy = favind / FAVORITECOMBO_PER_ROW;
9437 int32_t fc = (fy + yi) * FAVORITECOMBO_PER_ROW + fx + xi + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
9438
9439 if (cx + xi < 4 && cc < MAXCOMBOS && fx + xi < FAVORITECOMBO_PER_ROW && fy + yi < FAVORITECOMBO_PER_COLUMN)
9440 {
9441 if (favorite_combos[fc] < 0 || force)
9442 {
9443 favorite_combo_modes[fc] = dm_normal;
9444 favorite_combos[fc] = cc;
9445 }
9446 }
9447 }
9448 }
9449 }
9450
9451 void onRCSelectCombo(int32_t c)
9452 {
9453 int32_t drawmap, drawscr;
9454
9455 if(CurrentLayer==0)
9456 {
9457 drawmap=Map.getCurrMap();
9458 drawscr=Map.getCurrScr();
9459 }
9460 else
9461 {
9462 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9463 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9464 }
9465 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9466 if(!draw_mapscr) return;
9467
9468 Combo=draw_mapscr->data[c];
9469 if(AutoBrush)
9470 BrushWidth = BrushHeight = 1;
9471 }
9472
9473 void onRCScrollToombo(int32_t c)
9474 {
9475 int32_t drawmap, drawscr;
9476
9477 if(CurrentLayer==0)
9478 {
9479 drawmap=Map.getCurrMap();
9480 drawscr=Map.getCurrScr();
9481 }
9482 else
9483 {
9484 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9485 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9486 }
9487 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9488 if(!draw_mapscr) return;
9489
9490 auto& sqr = combolist[current_combolist];
9491 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
9492 }
9493
9494 enum
9495 {
9496 MENUID_RCSCREEN_PASTE,
9497 MENUID_RCSCREEN_ADVPASTE,
9498 MENUID_RCSCREEN_SPECPASTE,
9499 };
9500
1/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
12 static NewMenu rc_menu_screen
9501 60 {
9502
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Copy Screen", onCopy },
9503
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "Paste Screen", &paste_screen_menu, MENUID_RCSCREEN_PASTE },
9504
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Advanced Paste", &paste_menu, MENUID_RCSCREEN_ADVPASTE },
9505
2/4
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
12 { "...Special Paste", &paste_item_menu, MENUID_RCSCREEN_SPECPASTE },
9506 };
9507
9508 void call_options_dlg();
9509 int32_t onOptions()
9510 {
9511 call_options_dlg();
9512 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9513 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9514 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9515 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9516 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9517 return D_O_K;
9518 }
9519
9520 void follow_twarp(int warpindex)
9521 {
9522 if(warpindex >= 4)
9523 {
9524 InfoDialog("Random Tile Warp",
9525 "This is a random tile warp combo, so it chooses"
9526 " randomly between the screen's four Tile Warps.").show();
9527 warpindex=zc_oldrand()&3;
9528 }
9529
9530 int32_t tm = Map.getCurrMap();
9531 int32_t ts = Map.getCurrScr();
9532 int32_t wt = Map.CurrScr()->tilewarptype[warpindex];
9533
9534 if(wt==wtCAVE || wt==wtNOWARP)
9535 {
9536 char buf[56];
9537 InfoDialog(warptype_string[wt],fmt::format("This screen's Tile Warp {} is set to {}, so it doesn't lead to another screen.",'A'+warpindex,warptype_string[wt]));
9538 return;
9539 }
9540
9541 Map.dowarp(0,warpindex);
9542
9543 if(ts!=Map.getCurrScr() || tm!=Map.getCurrMap())
9544 {
9545 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(warpindex*2))&3;
9546 FlashWarpClk = 32;
9547 }
9548 }
9549 void edit_twarp(int warpindex)
9550 {
9551 if(warpindex>=4)
9552 {
9553 InfoDialog("Random Tile Warp",
9554 "This is a random tile warp combo, so it chooses"
9555 " randomly between the screen's four Tile Warps.").show();
9556 warpindex=zc_oldrand()&3;
9557 }
9558
9559 if(warpindex > -1 && warpindex < 4)
9560 onTileWarpIndex(warpindex);
9561 }
9562
9563 int toggle_linked_scrolling()
9564 {
9565 LinkedScroll = LinkedScroll ? 0 : 1;
9566 zc_set_config("zquest","linked_comboscroll",LinkedScroll);
9567 return D_O_K;
9568 }
9569 void on_scroll_cpane()
9570 {
9571 switch (draw_mode)
9572 {
9573 case dm_alias:
9574 combo_alistpos[current_comboalist] = scrollto_alias(combo_apos);
9575 break;
9576 case dm_cpool:
9577 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
9578 break;
9579 case dm_auto:
9580 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
9581 break;
9582 default:
9583 First[current_combolist] = scrollto_cmb(Combo);
9584 break;
9585 }
9586 }
9587 void on_edit_cpane()
9588 {
9589 switch (draw_mode)
9590 {
9591 case dm_alias:
9592 onEditComboAlias();
9593 break;
9594 case dm_cpool:
9595 onEditComboPool();
9596 break;
9597 case dm_auto:
9598 onEditAutoCombo();
9599 break;
9600 default:
9601 reset_combo_animations();
9602 reset_combo_animations2();
9603 edit_combo(Combo, true, CSet);
9604 setup_combo_animations();
9605 setup_combo_animations2();
9606 break;
9607 }
9608 }
9609 void on_cpane_page()
9610 {
9611 switch(draw_mode)
9612 {
9613 case dm_normal:
9614 combo_screen(Combo>>8,Combo);
9615 break;
9616 case dm_alias:
9617 call_alias_pages(combo_apos);
9618 break;
9619 case dm_auto:
9620 call_autoc_pages(combo_auto_pos);
9621 break;
9622 case dm_cpool:
9623 call_cpool_pages(combo_pool_pos);
9624 break;
9625 }
9626 }
9627 void open_cpane_tilepage()
9628 {
9629 onGotoTiles(combobuf[Combo].o_tile);
9630 }
9631 static int _clicked_fav = 0;
9632 void fav_rc_remove()
9633 {
9634 favorite_combo_modes[_clicked_fav] = dm_normal;
9635 favorite_combos[_clicked_fav] = -1;
9636 saved = false;
9637 }
9638 void popup_favorites_rc(int f, int x, int y)
9639 {
9640 _clicked_fav = f;
9641 string type;
9642 switch (draw_mode)
9643 {
9644 case dm_alias:
9645 type = "Alias";
9646 break;
9647 case dm_cpool:
9648 type = "Pool";
9649 break;
9650 case dm_auto:
9651 type = "Autocombo";
9652 break;
9653 case dm_normal:
9654 type = "Combo";
9655 break;
9656 default: return;
9657 }
9658 NewMenu rcmenu
9659 {
9660 { fmt::format("Scroll to {}", type), on_scroll_cpane },
9661 { fmt::format("Edit {}", type), on_edit_cpane },
9662 { fmt::format("Open {} Page", type), on_cpane_page },
9663 { fmt::format("Remove Fav {}", type), fav_rc_remove },
9664 };
9665 switch (draw_mode)
9666 {
9667 case dm_normal:
9668 rcmenu.add({
9669 {},
9670 { "Open Tile Page", open_cpane_tilepage },
9671 });
9672 break;
9673 }
9674 rcmenu.pop(x, y);
9675 }
9676 void popup_cpane_rc(int x, int y)
9677 {
9678 string type;
9679 switch (draw_mode)
9680 {
9681 case dm_alias:
9682 type = "Alias";
9683 break;
9684 case dm_cpool:
9685 type = "Pool";
9686 break;
9687 case dm_auto:
9688 type = "Autocombo";
9689 break;
9690 case dm_normal:
9691 type = "Combo";
9692 break;
9693 default: return;
9694 }
9695 NewMenu rcmenu;
9696 switch(draw_mode)
9697 {
9698 case dm_normal:
9699 rcmenu.add({
9700 { fmt::format("Edit {}", type), on_edit_cpane },
9701 { fmt::format("Open {} Page", type), on_cpane_page },
9702 { "Open Tile Page", open_cpane_tilepage },
9703 { "Combo Locations", onComboLocationReport },
9704 {},
9705 { "Scroll to Page...", onGotoPage },
9706 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9707 });
9708 break;
9709 case dm_alias:
9710 case dm_cpool:
9711 case dm_auto:
9712 rcmenu.add({
9713 { fmt::format("Edit {}", type), on_edit_cpane },
9714 { fmt::format("Open {} Page", type), on_cpane_page },
9715 {},
9716 { "Scroll to Page...", onGotoPage },
9717 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9718 });
9719 break;
9720 }
9721 rcmenu.pop(x, y);
9722 }
9723
9724 void set_brush_width(int32_t width)
9725 {
9726 BrushWidth = width;
9727 for(int q = 0; q < brush_width_menu.size(); ++q)
9728 brush_width_menu.at(q)->select(q==BrushWidth-1);
9729 refresh(rALL);
9730 }
9731
9732 void set_brush_height(int32_t height)
9733 {
9734 BrushHeight = height;
9735 for(int q = 0; q < brush_height_menu.size(); ++q)
9736 brush_height_menu.at(q)->select(q==BrushHeight-1);
9737 refresh(rALL);
9738 }
9739
9740 1 void restore_mouse()
9741 {
9742 1 ComboBrushPause=1;
9743 1 MouseSprite::set(ZQM_NORMAL);
9744 1 }
9745
9746 static int32_t comboa_cnt=0;
9747 static int32_t combop_cnt=0;
9748 static int32_t layer_cnt=0;
9749
9750 static char paste_ffc_menu_text[21];
9751 static char paste_ffc_menu_text2[21];
9752 static char follow_warp_menu_text[21];
9753 static char follow_warp_menu_text2[21];
9754
9755 static int fake_mouse_b(){return 0;}
9756 static int (*mouseb_proc)();
9757 static bool killed_mouse = false;
9758 void zq_killmouse()
9759 {
9760 if(killed_mouse) return;
9761 mouseb_proc = gui_mouse_b;
9762 gui_mouse_b = fake_mouse_b;
9763 killed_mouse = true;
9764 }
9765 void zq_restoremouse()
9766 {
9767 if(!killed_mouse) return;
9768 gui_mouse_b = mouseb_proc;
9769 killed_mouse = false;
9770 }
9771
9772
9773 void domouse()
9774 {
9775 static int mouse_down = 0;
9776 static int32_t scrolldelay = 0;
9777 auto mousexy = zc_get_mouse();
9778 auto x = mousexy.first;
9779 auto y = mousexy.second;
9780 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
9781 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
9782 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
9783 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
9784 int32_t cx=(x-startx)/(16*mapscreen_single_scale);
9785 int32_t cy=(y-starty)/(16*mapscreen_single_scale);
9786 ComboPosition combo_pos = {cx, cy};
9787
9788 if (draw_mode == dm_auto)
9789 {
9790 if (combo_pos != mouse_combo_pos)
9791 combobrushoverride = get_autocombo_floating_cid(combo_pos, false);
9792 }
9793 else
9794 combobrushoverride = -1;
9795
9796 mouse_combo_pos = combo_pos;
9797 update_combobrush();
9798
9799 ++scrolldelay;
9800
9801 bool x_on_list = false;
9802 for(auto q = 0; q < num_combo_cols; ++q)
9803 {
9804 if((x>=combolist[q].x) && (x<combolist[q].x+(combolist[q].xscale*combolist[q].w)))
9805 {
9806 x_on_list = true;
9807 break;
9808 }
9809 }
9810 if(MouseScroll && x_on_list && (key[KEY_LSHIFT] || key[KEY_RSHIFT] || (scrolldelay&3)==0))
9811 {
9812 int32_t test_list=0;
9813
9814 for(test_list=0; test_list<num_combo_cols; ++test_list)
9815 {
9816 if((x>=combolist[test_list].x) && (x<combolist[test_list].x+(combolist[test_list].xscale*combolist[test_list].w)))
9817 {
9818 break;
9819 }
9820 }
9821
9822 if(test_list<num_combo_cols)
9823 {
9824 if(y>=combolist[test_list].y-mouse_scroll_h && y<=combolist[test_list].y && First[test_list])
9825 {
9826 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9827 {
9828 First[test_list]=0;
9829 }
9830 else if(CHECK_CTRL_CMD)
9831 {
9832 First[test_list]-=zc_min(First[test_list],256);
9833 }
9834 else if(key[KEY_ALT] || key[KEY_ALTGR])
9835 {
9836 First[test_list]-=zc_min(First[test_list],(combolist[test_list].w*combolist[test_list].h));
9837 }
9838 else
9839 {
9840 First[test_list]-=zc_min(First[test_list],combolist[test_list].w);
9841 }
9842 }
9843
9844 if(y>=combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)-1 && y<combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)+mouse_scroll_h-1 && First[test_list]<(MAXCOMBOS-(combolist[test_list].w*combolist[test_list].h)))
9845 {
9846 int32_t offset = combolist[test_list].w*combolist[test_list].h;
9847
9848 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9849 {
9850 First[test_list]=MAXCOMBOS-offset;
9851 }
9852 else if(CHECK_CTRL_CMD)
9853 {
9854 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+256);
9855 }
9856 else if(key[KEY_ALT] || key[KEY_ALTGR])
9857 {
9858 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+ offset);
9859 }
9860 else
9861 {
9862 First[test_list] = zc_min(MAXCOMBOS - offset, First[test_list] + combolist[test_list].w);
9863 }
9864 }
9865 }
9866 }
9867
9868 // The screen for this combo_pos, layer 0. Used to access ffcs.
9869 mapscr* scr = Map.Scr(combo_pos);
9870 // The screen for this combo_pos at the CurrentLayer. Could be same as scr.
9871 mapscr* draw_mapscr = scr && CurrentLayer ? Map.Scr(combo_pos, CurrentLayer) : scr;
9872 int c = combo_pos.truncate();
9873 set_active_visible_screen(scr);
9874
9875 //-------------
9876 //tooltip stuff
9877 //-------------
9878 if (active_visible_screen && isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
9879 {
9880 static int mapscr_tooltip_id = ttip_register_id();
9881 bool did_ffttip = false;
9882 int num_ffcs = scr->numFFC();
9883 for(int32_t i=num_ffcs-1; i>=0; i--)
9884 if(scr->ffcs[i].data !=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
9885 {
9886 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
9887 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
9888 int32_t ffw = scr->ffTileWidth(i)*16;
9889 int32_t ffh = scr->ffTileHeight(i)*16;
9890 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
9891 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
9892
9893 if(cx2 >= ffx && cx2 < ffx+ffw && cy2 >= ffy && cy2 < ffy+ffh)
9894 {
9895 // FFC tooltip
9896 if(tooltip_current_ffc != i)
9897 {
9898 clear_tooltip();
9899 }
9900
9901 tooltip_current_ffc = i;
9902 char msg[1024] = {0};
9903 auto& ff = scr->ffcs[i];
9904 sprintf(msg,"FFC: %d Combo: %d\nCSet: %d Type: %s\nScript: %s",
9905 i+1, ff.data,ff.data,
9906 combo_class_buf[combobuf[ff.data].type].name,
9907 (ff.script<=0 ? "(None)" : ffcmap[ff.script-1].scriptname.substr(0,400).c_str()));
9908 ttip_install(mapscr_tooltip_id, msg, startxint+(ffx*mapscreen_single_scale), startyint+(ffy*mapscreen_single_scale), ffw*mapscreen_single_scale, ffh*mapscreen_single_scale, x, y);
9909 did_ffttip = true;
9910 break;
9911 }
9912 }
9913 if(!did_ffttip)
9914 {
9915 if(unsigned(c) < 176 && draw_mapscr && !gui_mouse_b())
9916 {
9917 int cid = draw_mapscr->data[c];
9918 newcombo const& cmb = combobuf[cid];
9919 std::ostringstream oss;
9920 int cs = draw_mapscr->cset[c];
9921 int sflag = draw_mapscr->sflag[c];
9922 oss << "Pos: " << c
9923 << "\nCombo: " << cid
9924 << "\nCSet: " << cs;
9925 if(sflag || cmb.flag)
9926 oss << "\nFlags: " << sflag << ", " << (int)cmb.flag;
9927 if(cmb.type)
9928 oss << "\nCombo type: " << combo_class_buf[cmb.type].name;
9929 if(cmb.label[0])
9930 oss << "\nLabel: " << cmb.label;
9931 ttip_install(mapscr_tooltip_id, oss.str().c_str(), startxint+(cx*16*mapscreen_single_scale), startyint+(cy*16*mapscreen_single_scale), 16*mapscreen_single_scale, 16*mapscreen_single_scale, x, y);
9932 }
9933 }
9934 }
9935
9936 {
9937 size_and_pos* squares[4] = {&itemsqr_pos,&stairsqr_pos,&warparrival_pos,&flagsqr_pos};
9938 for(int32_t j=0; j<4; j++)
9939 {
9940 auto& square = *squares[j];
9941 if(square.rect(x,y))
9942 {
9943 char msg[160];
9944 sprintf(msg,
9945 j==0 ? "Item Location" :
9946 j==1 ? "Stairs Secret\nTriggered when a Trigger Push Block is pushed." :
9947 j==2 ? "Arrival Square\nPlayer's location when they begin/resume the game." :
9948 "Combo Flags");
9949 update_tooltip(x,y,square,msg);
9950 }
9951 }
9952
9953 // Warp Returns
9954 for(int32_t j=0; j<4; j++)
9955 {
9956 size_and_pos& wret = warpret_pos[j];
9957 if(wret.rect(x,y))
9958 {
9959 char msg[160];
9960 sprintf(msg,"Warp Return Square %c\nPlayer's destination after warping to this screen.",(char)('A'+j));
9961 update_tooltip(x,y,wret,msg);
9962 }
9963 }
9964
9965 // Enemies
9966 if(enemy_prev_pos.rect(x,y))
9967 {
9968 char msg[160];
9969 sprintf(msg,"Enemies that appear on this screen.");
9970 update_tooltip(x,y,enemy_prev_pos,msg);
9971 }
9972
9973 int32_t cmd = commands_list.rectind(x,y);
9974 if(cmd > -1)
9975 {
9976 update_tooltip(x,y,commands_list.subsquare(cmd),
9977 fmt::format("Fav Command {}: {}\n{}", cmd,
9978 get_hotkey_name(favorite_commands[cmd]),
9979 get_hotkey_helptext(favorite_commands[cmd])).c_str());
9980 }
9981 }
9982
9983 if(draw_mode==dm_alias)
9984 {
9985 for(int32_t j=0; j<num_combo_cols; ++j)
9986 {
9987 auto& sqr = comboaliaslist[j];
9988 auto ind = sqr.rectind(x,y);
9989 if(ind > -1)
9990 {
9991 auto c2=ind+combo_alistpos[j];
9992 char msg[80];
9993 sprintf(msg, "Combo alias %d", c2);
9994 update_tooltip(x,y,sqr.subsquare(ind), msg);
9995 }
9996 }
9997 }
9998 else if(draw_mode==dm_cpool)
9999 {
10000 for(int32_t j=0; j<num_combo_cols; ++j)
10001 {
10002 auto& sqr = comboaliaslist[j];
10003 auto ind = sqr.rectind(x,y);
10004 if(ind > -1)
10005 {
10006 auto c2=ind+combo_pool_listpos[j];
10007 char msg[80];
10008 sprintf(msg, "Combo Pool %d", c2);
10009 update_tooltip(x,y,sqr.subsquare(ind), msg);
10010 }
10011 }
10012 if(cpool_prev_visible && combopool_prevbtn.rect(x,y))
10013 {
10014 if(do_layer_button_reset(combopool_prevbtn.x,combopool_prevbtn.y,
10015 combopool_prevbtn.w,combopool_prevbtn.h,
10016 weighted_cpool ? "Weighted" : "Unweighted",0,true))
10017 {
10018 weighted_cpool = !weighted_cpool;
10019 }
10020 }
10021 }
10022 else if (draw_mode == dm_auto)
10023 {
10024 for (int32_t j = 0; j < num_combo_cols; ++j)
10025 {
10026 auto& sqr = comboaliaslist[j];
10027 auto ind = sqr.rectind(x, y);
10028 if (ind > -1)
10029 {
10030 auto c2 = ind + combo_auto_listpos[j];
10031 char msg[80];
10032 sprintf(msg, "Auto Combo %d", c2);
10033 update_tooltip(x, y, sqr.subsquare(ind), msg);
10034 }
10035 }
10036 }
10037 else
10038 {
10039 if(combo_preview.rect(x,y))
10040 {
10041 auto str = "Combo Colors:\n"+get_combo_colornames(Combo,CSet);
10042 update_tooltip(x,y,combo_preview,str.c_str());
10043 }
10044 else if(comboprev_buf[0] && combo_preview_text1.rect(x,y))
10045 {
10046 update_tooltip(x,y,combo_preview_text1,comboprev_buf);
10047 }
10048 else if(comboprev_buf2[0] && combo_preview_text2.rect(x,y))
10049 {
10050 update_tooltip(x,y,combo_preview_text2,comboprev_buf2);
10051 }
10052 else for(int32_t j=0; j<num_combo_cols; ++j)
10053 {
10054 auto& sqr = combolist[j];
10055 auto ind = sqr.rectind(x,y);
10056 if(ind > -1)
10057 {
10058 int32_t c2=ind+First[j];
10059 std::ostringstream oss;
10060 newcombo const& cmb = combobuf[c2];
10061 oss << "Combo " << c2 << ": " << combo_class_buf[cmb.type].name;
10062 if(cmb.flag != 0)
10063 oss << "\nInherent flag: " << ZI.getMapFlagName(cmb.flag);
10064 if(!cmb.label.empty())
10065 oss << "\nLabel: " << cmb.label;
10066
10067 update_tooltip(x,y,sqr.subsquare(ind), oss.str().c_str());
10068 }
10069 }
10070 }
10071
10072 if (favorites_list.rect(x, y))
10073 {
10074 int32_t f = favorites_list.rectind(x, y);
10075 int32_t row = f / favorites_list.w;
10076 int32_t col = f % favorites_list.w;
10077 f = (row * FAVORITECOMBO_PER_ROW) + col;
10078
10079 auto& sqr = favorites_list.subsquare(col, row);
10080
10081 char buf[180];
10082 if (favorite_combos[f] == -1)
10083 sprintf(buf, "Fav Combo %d\nEmpty", f);
10084 else
10085 {
10086 switch (favorite_combo_modes[f])
10087 {
10088 case dm_alias:
10089 sprintf(buf, "Fav Combo %d\nAlias %d", f, favorite_combos[f]);
10090 break;
10091 case dm_cpool:
10092 sprintf(buf, "Fav Combo %d\nPool %d", f, favorite_combos[f]);
10093 break;
10094 case dm_auto:
10095 sprintf(buf, "Fav Combo %d\nAutocombo %d", f, favorite_combos[f]);
10096 break;
10097 default:
10098 sprintf(buf, "Fav Combo %d\nCombo %d", f, favorite_combos[f]);
10099 }
10100 }
10101 update_tooltip(x, y, sqr, buf);
10102 }
10103
10104 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
10105 auto ind = real_mini.rectind(x,y);
10106 if(ind > -1)
10107 {
10108 char buf[80];
10109 sprintf(buf,"0x%02X (%d)", ind, ind);
10110 ttip_install(minimap_tooltip_id, buf, real_mini.subsquare(ind), real_mini.x+real_mini.tw(), real_mini.y-16);
10111 ttip_set_highlight_thickness(minimap_tooltip_id, zoomed_minimap ? 2 : 1);
10112 // Make sure always above the other tooltip items to the right of the map (even in big map mode).
10113 ttip_set_z_index(minimap_tooltip_id, 100);
10114 ttip_clear_timer();
10115 }
10116 else
10117 {
10118 ttip_uninstall(minimap_tooltip_id);
10119 }
10120
10121 // Mouse clicking stuff
10122 int real_mb = gui_mouse_b();
10123 int mb = real_mb & ~mouse_down; //Only handle clicks that have not been handled already
10124 auto mz = mouse_z;
10125 bool lclick = mb&1;
10126 bool rclick = mb&2;
10127
10128 if (mb && hotkeys_is_active())
10129 {
10130 hotkeys_toggle_display(false);
10131 while (gui_mouse_b())
10132 {
10133 custom_vsync();
10134 }
10135 return;
10136 }
10137
10138 FONT* tfont = font;
10139 if(zoomed_minimap)
10140 {
10141 if((lclick||rclick) && !minimap_zoomed.rect(x,y))
10142 {
10143 // 'Clicked off'
10144 mmap_set_zoom(false);
10145 goto domouse_doneclick;
10146 }
10147 }
10148
10149 if(real_mb==0)
10150 {
10151 mouse_down = 0;
10152 canfill=true;
10153 }
10154 else if(lclick || rclick)
10155 {
10156 //on the minimap
10157 if(real_mini.rect(x,y))
10158 {
10159 if(lclick)
10160 select_scr();
10161 else if(rclick && !(mouse_down&2))
10162 {
10163 mmap_set_zoom(!zoomed_minimap);
10164 }
10165 goto domouse_doneclick;
10166 }
10167
10168 if(zoomed_minimap && minimap_zoomed.rect(x,y))
10169 goto domouse_doneclick; //Eat clicks
10170
10171 //on the map tabs
10172 font = get_custom_font(CFONT_GUI);
10173 for(int32_t btn=0; btn<mappage_count; ++btn)
10174 {
10175 char tbuf[15];
10176 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
10177 auto& sqr = map_page_bar[btn];
10178 if(sqr.rect(x,y))
10179 {
10180 if(do_layer_button_reset(sqr.x,sqr.y,sqr.w,sqr.h,tbuf,(btn==current_mappage?D_SELECTED:0)))
10181 {
10182 draw_layer_button(screen, sqr.x,sqr.y,sqr.w,sqr.h,tbuf,D_SELECTED);
10183 map_page[current_mappage].map=Map.getCurrMap();
10184 map_page[current_mappage].screen=Map.getCurrScr();
10185 current_mappage=btn;
10186 Map.setCurrMap(map_page[current_mappage].map);
10187 Map.setCurrScr(map_page[current_mappage].screen);
10188 rebuild_trans_table(); //Woo
10189 }
10190 goto domouse_doneclick;
10191 }
10192 }
10193
10194 if(compactbtn.rect(x,y))
10195 {
10196 if(do_text_button(compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact"));
10197 toggle_is_compact();
10198 goto domouse_doneclick;
10199 }
10200
10201 if(!zoom_in_btn_disabled && zoominbtn.rect(x,y))
10202 {
10203 if(do_text_button(zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+"))
10204 change_mapscr_zoom(-1);
10205 goto domouse_doneclick;
10206 }
10207
10208 if(!zoom_out_btn_disabled && zoomoutbtn.rect(x,y))
10209 {
10210 if(do_text_button(zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-"))
10211 change_mapscr_zoom(1);
10212 goto domouse_doneclick;
10213 }
10214
10215 font = get_zc_font(font_lfont_l);
10216 if(combo_merge_btn.rect(x,y))
10217 {
10218 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
10219 if(do_text_button(combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<"))
10220 {
10221 toggle_merged_mode();
10222 }
10223 goto domouse_doneclick;
10224 }
10225
10226 if(favorites_zoombtn.rect(x,y))
10227 {
10228 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
10229 if(do_text_button(favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+"))
10230 {
10231 toggle_favzoom_mode();
10232 }
10233 goto domouse_doneclick;
10234 }
10235 else if(favorites_x.rect(x,y))
10236 {
10237 if(do_text_button(favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X"))
10238 {
10239 AlertDialog("Clear Favorite Combos",
10240 "Are you sure you want to clear all favorite combos?",
10241 [&](bool ret,bool)
10242 {
10243 if(ret)
10244 {
10245 for(auto q = 0; q < MAXFAVORITECOMBOS; ++q)
10246 {
10247 favorite_combos[q] = -1;
10248 favorite_combo_modes[q] = dm_normal;
10249 }
10250 saved = false;
10251 refresh(rFAVORITES);
10252 }
10253 }).show();
10254 }
10255 goto domouse_doneclick;
10256 }
10257 else if(favorites_infobtn.rect(x,y))
10258 {
10259 if(do_text_button(favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?"))
10260 {
10261 InfoDialog("Favorite Combos",
10262 "On LClick (empty): Sets clicked favorite to the current combo."
10263 "\nOn LClick: Sets current combo to clicked favorite."
10264 "\nShift+LClick: Sets clicked favorite to current combo."
10265 "\nCtrl+LClick: Clears clicked favorite."
10266 "\nAlt+LClick: Scrolls to clicked favorite."
10267 "\nRClick: Opens context menu."
10268 "\n\nClick the Page buttons (<-/->) to cycle between pages (RClick to jump to a page)"
10269 "\nClick the Zoom button (+/-) to toggle zoom level."
10270 "\nClick the X button to clear all favorite combos.").show();
10271 }
10272 goto domouse_doneclick;
10273 }
10274 else if(favorites_pgleft.rect(x,y))
10275 {
10276 if (do_text_button(favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-"))
10277 {
10278 if (rclick)
10279 {
10280 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10281 FavoriteComboPage = vbound(*val-1, 0, 8);
10282 }
10283 else
10284 FavoriteComboPage = FavoriteComboPage == 0 ? 8 : --FavoriteComboPage;
10285 reload_zq_gui();
10286 }
10287 goto domouse_doneclick;
10288 }
10289 else if(favorites_pgright.rect(x,y))
10290 {
10291 if (do_text_button(favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->"))
10292 {
10293 if (rclick)
10294 {
10295 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10296 FavoriteComboPage = vbound(*val-1, 0, 8);
10297 }
10298 else
10299 FavoriteComboPage = FavoriteComboPage == 8 ? 0 : ++FavoriteComboPage;
10300 reload_zq_gui();
10301 }
10302 goto domouse_doneclick;
10303 }
10304
10305 if(commands_zoombtn.rect(x,y))
10306 {
10307 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
10308 if(do_text_button(commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+"))
10309 {
10310 toggle_cmdzoom_mode();
10311 }
10312 goto domouse_doneclick;
10313 }
10314 else if(commands_x.rect(x,y))
10315 {
10316 if(do_text_button(commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X"))
10317 {
10318 AlertDialog("Clear Favorite Commands",
10319 "Are you sure you want to clear all favorite commands?",
10320 [&](bool ret,bool)
10321 {
10322 if(ret)
10323 {
10324 char buf[20];
10325 for(auto q = 0; q < MAXFAVORITECOMMANDS; ++q)
10326 {
10327 write_fav_command(q,0);
10328 }
10329 refresh(rFAVORITES);
10330 }
10331 }).show();
10332 }
10333 goto domouse_doneclick;
10334 }
10335 else if(commands_infobtn.rect(x,y))
10336 {
10337 if(do_text_button(commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?"))
10338 {
10339 InfoDialog("Favorite Commands",
10340 "On LClick (empty): Choose a favorite command"
10341 "\nOn LClick: Runs the favorite command"
10342 "\nShift+Click: Choose a favorite command"
10343 "\nRClick: Choose a favorite command"
10344 "\nCtrl+Click: Clears clicked command"
10345 "\nAlt+Click: Shows info on the favorite command"
10346 "\n\nClick the Zoom button (+/-) to toggle zoom level"
10347 "\nClick the X button to clear all favorite commands").show();
10348 }
10349 goto domouse_doneclick;
10350 }
10351 font=tfont;
10352
10353 // On the layer panel
10354 font = get_custom_font(CFONT_GUI);
10355 for(int32_t i=0; i<=6; ++i)
10356 {
10357 int32_t spacing_offs = is_compact ? 2 : 10;
10358 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
10359 int32_t ry = layer_panel.y;
10360
10361 if ((i == 0 || mapscreen_valid_layers[i - 1]) && isinRect(x,y,rx,ry,rx+layerpanel_buttonwidth-1,ry+layerpanel_buttonheight-1))
10362 {
10363 char tbuf[15];
10364
10365 if (Map.getViewSize() > 1)
10366 {
10367 sprintf(tbuf, "%d", i);
10368 }
10369 else if (i != 0 && mapscreen_valid_layers[i - 1])
10370 {
10371 if (is_compact)
10372 {
10373 sprintf(tbuf, "%s%d %d:%02X",
10374 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10375 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10376 }
10377 else
10378 {
10379 sprintf(tbuf, "%s%d (%d:%02X)",
10380 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10381 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10382 }
10383 }
10384 else
10385 {
10386 sprintf(tbuf, "%d", i);
10387 }
10388
10389 if(do_text_button(rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf))
10390 {
10391 CurrentLayer = i;
10392 goto domouse_doneclick;
10393 }
10394 }
10395
10396 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
10397 if(isinRect(x,y,rx+layerpanel_buttonwidth+1,ry+cbyofs,rx+layerpanel_buttonwidth+1+layerpanel_checkbox_wid-1,ry+2+layerpanel_checkbox_hei-1))
10398 {
10399 do_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]);
10400 goto domouse_doneclick;
10401 }
10402 }
10403 font=tfont;
10404
10405 //Uses lclick/rclick separately
10406
10407 //on the map screen
10408 if(isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
10409 {
10410 if (lclick)
10411 {
10412 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
10413 }
10414
10415 if (draw_mode == dm_auto)
10416 {
10417 if (CHECK_CTRL_CMD)
10418 {
10419 if (canfill)
10420 {
10421 switch (fill_type)
10422 {
10423 case 0:
10424 flood();
10425 break;
10426
10427 case 1:
10428 fill_4();
10429 break;
10430
10431 case 2:
10432 fill_8();
10433 break;
10434
10435 case 3:
10436 fill2_4();
10437 break;
10438
10439 case 4:
10440 fill2_8();
10441 break;
10442 }
10443
10444 canfill = false;
10445 }
10446 }
10447 else
10448 draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10449 }
10450 else if (scr && lclick)
10451 {
10452 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10453 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10454
10455 // Move items
10456 if (scr->hasitem && active_visible_screen)
10457 {
10458 int32_t ix = scr->itemx + active_visible_screen->dx * 256;
10459 int32_t iy = scr->itemy + active_visible_screen->dy * 176;
10460
10461 if(cx2 >= ix && cx2 < ix+16 && cy2 >= iy && cy2 < iy+16)
10462 doxypos(scr->itemx, scr->itemy, 11, SNAP_HALF, SNAP_NONE, true, 0, 0, 16, 16);
10463 }
10464
10465 // Move FFCs
10466 int num_ffcs = scr->numFFC();
10467 for(int32_t i=num_ffcs-1; i>=0; i--)
10468 if(scr->ffcs[i].data !=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
10469 {
10470 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10471 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10472
10473 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10474 {
10475 moveffc(i, cx2, cy2);
10476 break;
10477 }
10478 }
10479
10480 if(key[KEY_ALT]||key[KEY_ALTGR])
10481 {
10482 if (!draw_mapscr) return;
10483
10484 Combo=draw_mapscr->data[c];
10485 if(AutoBrush)
10486 BrushWidth = BrushHeight = 1;
10487 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
10488 CSet=draw_mapscr->cset[c];
10489 if(CHECK_CTRL_CMD)
10490 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
10491 }
10492 else if(CHECK_CTRL_CMD)
10493 {
10494 if(canfill)
10495 {
10496 switch(fill_type)
10497 {
10498 case 0:
10499 flood();
10500 break;
10501
10502 case 1:
10503 fill_4();
10504 break;
10505
10506 case 2:
10507 fill_8();
10508 break;
10509
10510 case 3:
10511 fill2_4();
10512 break;
10513
10514 case 4:
10515 fill2_8();
10516 break;
10517 }
10518
10519 canfill=false;
10520 }
10521 }
10522 else draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10523 }
10524 else if (scr && rclick)
10525 {
10526 ComboBrushPause=1;
10527 refresh(rMAP);
10528 restore_mouse();
10529 ComboBrushPause=0;
10530
10531 bool clickedffc = false;
10532
10533 // FFC right-click menu
10534 // This loop also serves to find the free ffc with the smallest slot number.
10535 int num_ffcs = scr->numFFC();
10536 uint32_t earliestfreeffc = num_ffcs;
10537 for(int32_t i=num_ffcs-1; i>=0; i--)
10538 {
10539 auto data = scr->ffcs[i].data;
10540 if(data==0)
10541 {
10542 if(i < earliestfreeffc)
10543 earliestfreeffc = i;
10544 continue;
10545 }
10546
10547 if(clickedffc || !(scr->valid&mVALID))
10548 continue;
10549
10550 if(data!=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
10551 {
10552 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10553 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10554 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10555 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10556
10557 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10558 {
10559 NewMenu rcmenu
10560 {
10561 { "Copy FFC", [&](){Map.CopyFFC(active_visible_screen->screen, i);} },
10562 { "Paste FFC data", [&]()
10563 {
10564 bool didconfirm = false;
10565 AlertDialog("Confirm Paste",
10566 "Really replace the FFC with the data of the copied FFC?",
10567 [&](bool ret,bool)
10568 {
10569 if(ret)
10570 didconfirm = true;
10571 }).show();
10572 if(didconfirm)
10573 {
10574 auto set_ffc_data = Map.getCopyFFCData();
10575 set_ffc_data.x = scr->ffcs[i].x;
10576 set_ffc_data.y = scr->ffcs[i].y;
10577 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10578 }
10579 }, nullopt, Map.getCopyFFC() < 0 },
10580 { "Edit FFC", [&](){call_ffc_dialog(i, active_visible_screen->scr, active_visible_screen->screen);} },
10581 { "Clear FFC", [&]()
10582 {
10583 bool didconfirm = false;
10584 AlertDialog("Confirm Clear",
10585 "Really clear this Freeform Combo?",
10586 [&](bool ret,bool)
10587 {
10588 if(ret)
10589 didconfirm = true;
10590 }).show();
10591 if(didconfirm)
10592 {
10593 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, {
10594 .x = 0,
10595 .y = 0,
10596 .vx = 0,
10597 .vy = 0,
10598 .ax = 0,
10599 .ay = 0,
10600 .data = 0,
10601 .cset = 0,
10602 .delay = 0,
10603 .link = 0,
10604 .script = 0,
10605 .tw = 1,
10606 .th = 1,
10607 .ew = 16,
10608 .eh = 16,
10609 .flags = ffc_none,
10610 .initd = 0,
10611 });
10612 saved = false;
10613 }
10614 } },
10615 { "Snap to Grid", [&]()
10616 {
10617 int oldffx = scr->ffcs[i].x.getInt();
10618 int oldffy = scr->ffcs[i].y.getInt();
10619 int pos = COMBOPOS(oldffx,oldffy);
10620 int newffy = COMBOY(pos);
10621 int newffx = COMBOX(pos);
10622
10623 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
10624 set_ffc_data.x = newffx;
10625 set_ffc_data.y = newffy;
10626 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10627
10628 saved = false;
10629 } },
10630 };
10631 rcmenu.pop(x, y);
10632 clickedffc = true;
10633 break;
10634 }
10635 }
10636 }
10637
10638 // Combo right-click menu
10639 if(!clickedffc)
10640 {
10641 int warpindex = Map.warpindex(scr->data[c]);
10642 string txt_twarp_follow, txt_twarp_edit, txt_ffc_edit, txt_ffc_paste;
10643 bool show_ffcs = earliestfreeffc < MAXFFCS;
10644 bool dis_paste_ffc = Map.getCopyFFC() < 0;
10645 bool show_warps = warpindex > -1;
10646 bool show_warpback = Map.has_warpback();
10647 // FFC-specific options
10648 if(earliestfreeffc < MAXFFCS)
10649 {
10650 txt_ffc_edit = fmt::format("Edit New FFC {}",earliestfreeffc+1);
10651 if(Map.getCopyFFC()>-1)
10652 txt_ffc_paste = fmt::format("Paste FFC as FFC {}",earliestfreeffc+1);
10653 else
10654 txt_ffc_paste = "Paste FFC";
10655 }
10656
10657 if(warpindex > -1)
10658 {
10659 char letter = warpindex==4 ? 'R' : 'A'+warpindex;
10660 txt_twarp_follow = fmt::format("Follow Tile Warp {}",letter);
10661 txt_twarp_edit = fmt::format("Edit Tile Warp {}",letter);
10662 }
10663
10664 NewMenu draw_rc_menu
10665 {
10666 { "Select Combo", [&]()
10667 {
10668 Combo = draw_mapscr->data[c];
10669 if(AutoBrush)
10670 BrushWidth = BrushHeight = 1;
10671 }, nullopt, !draw_mapscr },
10672 { "Scroll to Combo", [&]()
10673 {
10674 First[current_combolist] = scrollto_cmb(draw_mapscr->data[c]);
10675 }, nullopt, !draw_mapscr },
10676 { "Edit Combo", [&]()
10677 {
10678 edit_combo(draw_mapscr->data[c],true,draw_mapscr->cset[c]);
10679 }, nullopt, !draw_mapscr },
10680 {},
10681 { "Replace All", [&](){replace(combo_pos);} },
10682 { "Draw Block", &draw_block_menu },
10683 { "Brush Settings ", &brush_menu },
10684 { "Set Fill Type ", &fill_menu },
10685 };
10686 if(show_warps || show_warpback)
10687 {
10688 draw_rc_menu.add_sep();
10689 if(show_warpback)
10690 draw_rc_menu.add({ "Warp Back", [&](){Map.warpback();} });
10691 if(show_warps)
10692 {
10693 draw_rc_menu.add({ txt_twarp_follow, [&](){follow_twarp(warpindex);} });
10694 draw_rc_menu.add({ txt_twarp_edit, [&](){edit_twarp(warpindex);} });
10695 }
10696 }
10697 if(show_ffcs)
10698 {
10699 draw_rc_menu.add_sep();
10700 draw_rc_menu.add({ txt_ffc_edit, [&]()
10701 {
10702 ffdata tempdat;
10703 // x, y are ints on ffdata (but ffc x, y are zfix), so *10000
10704 tempdat.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256) * 10000;
10705 tempdat.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176) * 10000;
10706 tempdat.data = Combo;
10707 tempdat.cset = CSet;
10708 call_ffc_dialog(earliestfreeffc, tempdat, active_visible_screen->scr, active_visible_screen->screen);
10709 } });
10710 draw_rc_menu.add({ txt_ffc_paste, [&]()
10711 {
10712 auto set_ffc_data = Map.getCopyFFCData();
10713 set_ffc_data.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256);
10714 set_ffc_data.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176);
10715 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, earliestfreeffc, set_ffc_data);
10716 }, nullopt, dis_paste_ffc });
10717 }
10718 draw_rc_menu.add_sep();
10719 draw_rc_menu.add({ "Screen", &rc_menu_screen });
10720 draw_rc_menu.pop(x,y);
10721 }
10722 }
10723 goto domouse_doneclick;
10724 }
10725
10726 //on the drawing mode button
10727 font = get_custom_font(CFONT_GUI);
10728 if(drawmode_btn.rect(x,y))
10729 {
10730 if(lclick)
10731 {
10732 if(do_text_button(drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode]))
10733 onDrawingMode();
10734 }
10735 else if(rclick)
10736 drawing_mode_menu.pop(x,y);
10737 goto domouse_doneclick;
10738 }
10739 font=tfont;
10740
10741 //Squares
10742 //
10743 set_active_visible_screen(Map.CurrScr());
10744 {
10745 if(squarepanel_swap_btn.rect(x,y))
10746 {
10747 toggle_compact_sqr_mode();
10748 goto domouse_doneclick;
10749 }
10750 if(squarepanel_up_btn.rect(x,y))
10751 {
10752 cycle_compact_sqr(false);
10753 goto domouse_doneclick;
10754 }
10755 if(squarepanel_down_btn.rect(x,y))
10756 {
10757 cycle_compact_sqr(true);
10758 goto domouse_doneclick;
10759 }
10760
10761 bool do_dummyxy = false;
10762 bool dummymode = key[KEY_LSHIFT] || key[KEY_RSHIFT];
10763
10764 if(itemsqr_pos.rect(x,y))
10765 {
10766 if(dummymode) do_dummyxy = true;
10767 else
10768 {
10769 onItem();
10770
10771 if(!rclick && Map.CurrScr()->hasitem)
10772 doxypos(Map.CurrScr()->itemx,Map.CurrScr()->itemy,11,SNAP_HALF,SNAP_NONE);
10773 goto domouse_doneclick;
10774 }
10775 }
10776
10777 if(stairsqr_pos.rect(x,y))
10778 {
10779 if(dummymode) do_dummyxy = true;
10780 else
10781 {
10782 doxypos(Map.CurrScr()->stairx,Map.CurrScr()->stairy,14,SNAP_WHOLE);
10783 goto domouse_doneclick;
10784 }
10785 }
10786
10787 if(warparrival_pos.rect(x,y))
10788 {
10789 if(dummymode) do_dummyxy = true;
10790 else
10791 {
10792 if(get_qr(qr_NOARRIVALPOINT))
10793 {
10794 info_dsa("Arrival Square",
10795 "The arrival square cannot be used unless the QR 'Use Warp Return "
10796 "Points Only' under 'Quest->Options->Combos' is disabled."
10797 "\nGenerally, this square only exists for compatibility purposes, and is not used"
10798 " in creating new quests.",
10799 "dsa_warparrival");
10800 }
10801 else doxypos(Map.CurrScr()->warparrivalx,Map.CurrScr()->warparrivaly,10,SNAP_HALF,SNAP_NONE);
10802 goto domouse_doneclick;
10803 }
10804 }
10805
10806 if(flagsqr_pos.rect(x,y))
10807 {
10808 if(dummymode) do_dummyxy = true;
10809 else
10810 {
10811 onFlags();
10812 goto domouse_doneclick;
10813 }
10814 }
10815
10816 for(auto q = 0; q < 4; ++q)
10817 {
10818 if(warpret_pos[q].rect(x,y))
10819 {
10820 if(dummymode) do_dummyxy = true;
10821 else
10822 {
10823 doxypos(Map.CurrScr()->warpreturnx[q],Map.CurrScr()->warpreturny[q],9,SNAP_HALF,SNAP_NONE);
10824 goto domouse_doneclick;
10825 }
10826 }
10827 }
10828
10829 if(enemy_prev_pos.rect(x,y))
10830 {
10831 if(dummymode) do_dummyxy = true;
10832 else
10833 {
10834 onEnemies();
10835 goto domouse_doneclick;
10836 }
10837 }
10838
10839 if(do_dummyxy)
10840 {
10841 byte x = 0, y = 0;
10842 showxypos_dummy = true;
10843 doxypos(x,y,13,SNAP_HALF,SNAP_NONE);
10844 goto domouse_doneclick;
10845 }
10846 }
10847
10848 if(draw_mode==dm_alias)
10849 {
10850 for(int32_t j=0; j<num_combo_cols; ++j)
10851 {
10852 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10853 {
10854 scrollup(j);
10855 goto domouse_doneclick;
10856 }
10857 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10858 {
10859 scrolldown(j);
10860 goto domouse_doneclick;
10861 }
10862 else if(comboaliaslist[j].rect(x,y))
10863 {
10864 select_comboa(j);
10865
10866 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10867 popup_cpane_rc(x, y);
10868 goto domouse_doneclick;
10869 }
10870 }
10871 }
10872 else if(draw_mode==dm_cpool)
10873 {
10874 for(int32_t j=0; j<num_combo_cols; ++j)
10875 {
10876 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10877 {
10878 scrollup(j);
10879 goto domouse_doneclick;
10880 }
10881 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10882 {
10883 scrolldown(j);
10884 goto domouse_doneclick;
10885 }
10886 else if(comboaliaslist[j].rect(x,y))
10887 {
10888 select_combop(j);
10889
10890 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10891 popup_cpane_rc(x, y);
10892 goto domouse_doneclick;
10893 }
10894 }
10895 }
10896 else if (draw_mode == dm_auto)
10897 {
10898 for (int32_t j = 0; j < num_combo_cols; ++j)
10899 {
10900 if (combolistscrollers[j].rectind(x, y) == 0 && !mouse_down)
10901 {
10902 scrollup(j);
10903 goto domouse_doneclick;
10904 }
10905 else if (combolistscrollers[j].rectind(x, y) == 1 && !mouse_down)
10906 {
10907 scrolldown(j);
10908 goto domouse_doneclick;
10909 }
10910 else if (comboaliaslist[j].rect(x, y))
10911 {
10912 select_autocombo(j);
10913
10914 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10915 popup_cpane_rc(x, y);
10916 goto domouse_doneclick;
10917 }
10918 }
10919 }
10920 else
10921 {
10922 for(int32_t j=0; j<num_combo_cols; ++j)
10923 {
10924 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10925 {
10926 scrollup(j);
10927 goto domouse_doneclick;
10928 }
10929 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10930 {
10931 scrolldown(j);
10932 goto domouse_doneclick;
10933 }
10934 else if(combolist[j].rect(x,y))
10935 {
10936 select_combo(j);
10937
10938 if(rclick && combolist[j].rect(gui_mouse_x(),gui_mouse_y()))
10939 popup_cpane_rc(x, y);
10940 goto domouse_doneclick;
10941 }
10942 }
10943 }
10944
10945 //on the favorites list
10946 if(favorites_list.rect(x,y))
10947 {
10948 if(lclick)
10949 {
10950 int32_t f=favorites_list.rectind(x,y);
10951 int32_t row=f/favorites_list.w;
10952 int32_t col=f%favorites_list.w;
10953 f = (row*FAVORITECOMBO_PER_ROW)+col;
10954 int32_t fp = f + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
10955
10956 bool dmcond = favorite_combos[fp] < 0;
10957 if((key[KEY_LSHIFT] || key[KEY_RSHIFT] || dmcond) && !(CHECK_CTRL_CMD))
10958 {
10959 int32_t tempcb=ComboBrush;
10960 ComboBrush=0;
10961
10962 while(gui_mouse_b())
10963 {
10964 x=gui_mouse_x();
10965 y=gui_mouse_y();
10966
10967 switch(draw_mode)
10968 {
10969 case dm_alias:
10970 if (favorite_combos[fp] != combo_apos || favorite_combo_modes[fp] != dm_alias)
10971 {
10972 favorite_combo_modes[fp] = dm_alias;
10973 favorite_combos[fp] = combo_apos;
10974 saved = false;
10975 }
10976 break;
10977 case dm_cpool:
10978 if (favorite_combos[fp] != combo_pool_pos || favorite_combo_modes[fp] != dm_cpool)
10979 {
10980 favorite_combo_modes[fp] = dm_cpool;
10981 favorite_combos[fp] = combo_pool_pos;
10982 saved = false;
10983 }
10984 break;
10985 case dm_auto:
10986 if (favorite_combos[fp] != combo_auto_pos || favorite_combo_modes[fp] != dm_auto)
10987 {
10988 favorite_combo_modes[fp] = dm_auto;
10989 favorite_combos[fp] = combo_auto_pos;
10990 saved = false;
10991 }
10992 break;
10993 default:
10994 if (favorite_combos[fp] != Combo || favorite_combo_modes[fp] != dm_normal)
10995 {
10996 if (BrushWidth > 1 || BrushHeight > 1)
10997 {
10998 add_favorite_combo_block(f, Combo, key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10999 break;
11000 }
11001 favorite_combo_modes[fp] = dm_normal;
11002 favorite_combos[fp] = Combo;
11003 saved = false;
11004 }
11005 }
11006
11007 custom_vsync();
11008 refresh(rALL | rFAVORITES);
11009 }
11010
11011 ComboBrush=tempcb;
11012 }
11013 else if(CHECK_CTRL_CMD)
11014 {
11015 int32_t tempcb=ComboBrush;
11016 ComboBrush=0;
11017
11018 while(gui_mouse_b())
11019 {
11020 x=gui_mouse_x();
11021 y=gui_mouse_y();
11022
11023 if(favorite_combos[fp]!=-1)
11024 {
11025 favorite_combo_modes[fp] = dm_normal;
11026 favorite_combos[fp]=-1;
11027 saved=false;
11028 }
11029
11030 custom_vsync();
11031 refresh(rALL | rFAVORITES);
11032 }
11033
11034 ComboBrush=tempcb;
11035 }
11036 else if(key[KEY_ALT] || key[KEY_ALTGR])
11037 {
11038 if(select_favorite())
11039 {
11040 switch(favorite_combo_modes[fp])
11041 {
11042 case dm_alias:
11043 combo_alistpos[current_comboalist]=scrollto_alias(combo_apos);
11044 break;
11045 case dm_cpool:
11046 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
11047 break;
11048 case dm_auto:
11049 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
11050 break;
11051 default:
11052 First[current_combolist]=scrollto_cmb(Combo);
11053 }
11054 }
11055 }
11056 else
11057 {
11058 select_favorite();
11059 }
11060 }
11061 else if(rclick)
11062 {
11063 bool valid=select_favorite();
11064
11065 if(valid)
11066 {
11067 int f = favorites_list.rectind(x,y);
11068 int row = f/favorites_list.w;
11069 int col = f%favorites_list.w;
11070 f = (row*FAVORITECOMBO_PER_ROW) + col + (FAVORITECOMBO_PER_PAGE * FavoriteComboPage);
11071 popup_favorites_rc(f, x, y);
11072 }
11073 }
11074 goto domouse_doneclick;
11075 }
11076
11077 //on the commands buttons
11078 int32_t cmd = commands_list.rectind(x,y);
11079 if(cmd > -1)
11080 {
11081 uint hkey = favorite_commands[cmd];
11082 bool shift=(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11083 bool ctrl=(CHECK_CTRL_CMD);
11084 bool alt=(key[KEY_ALT] || key[KEY_ALTGR]);
11085 bool dis = disabled_hotkey(hkey);
11086 auto& btn = commands_list.subsquare(cmd);
11087 if(!dis||rclick||shift||ctrl||alt)
11088 {
11089 FONT *tfont=font;
11090 font=get_custom_font(CFONT_FAVCMD);
11091 if(do_layer_button_reset(btn.x,btn.y,btn.w,btn.h,
11092 get_hotkey_name(hkey),
11093 selected_hotkey(hkey)?D_SELECTED:0,
11094 true))
11095 {
11096 font=tfont;
11097 if(alt)
11098 {
11099 show_hotkey_info(hkey);
11100 }
11101 else if(ctrl)
11102 {
11103 write_fav_command(cmd,0);
11104 }
11105 else if(rclick || shift || hkey==ZQKEY_NULL_KEY)
11106 {
11107 if(auto newkey = select_fav_command())
11108 write_fav_command(cmd,*newkey);
11109 }
11110 else
11111 {
11112 run_hotkey(hkey);
11113 }
11114 }
11115
11116 font=tfont;
11117 }
11118 goto domouse_doneclick;
11119 }
11120 }
11121
11122 domouse_doneclick:
11123 mouse_down |= mb&3;
11124
11125 if(mouse_z!=0)
11126 {
11127 int32_t z=0;
11128
11129 for(int32_t j=0; j<num_combo_cols; ++j)
11130 {
11131 z=abs(mouse_z);
11132
11133 if(key[KEY_ALT]||key[KEY_ALTGR])
11134 {
11135 z*=combolist[j].h;
11136 }
11137
11138
11139 if(draw_mode == dm_alias)
11140 {
11141 if(comboaliaslist[j].rect(x,y))
11142 {
11143 if(mouse_z<0) //scroll down
11144 {
11145 combo_alistpos[current_comboalist] = zc_min(MAXCOMBOALIASES - comboaliaslist[j].w*comboaliaslist[j].h,
11146 combo_alistpos[current_comboalist]+comboaliaslist[j].w*z);
11147 }
11148 else //scroll up
11149 {
11150 if(combo_alistpos[current_comboalist]>0)
11151 {
11152 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],comboaliaslist[j].w*z);
11153 }
11154 }
11155 goto domouse_donez;
11156 }
11157 }
11158 else if(draw_mode == dm_cpool)
11159 {
11160 if(comboaliaslist[j].rect(x,y))
11161 {
11162 if(mouse_z<0) //scroll down
11163 {
11164 combo_pool_listpos[current_cpoollist] = zc_min(MAXCOMBOPOOLS - comboaliaslist[j].w*comboaliaslist[j].h,
11165 combo_pool_listpos[current_cpoollist]+comboaliaslist[j].w*z);
11166 }
11167 else //scroll up
11168 {
11169 if(combo_pool_listpos[current_cpoollist]>0)
11170 {
11171 combo_pool_listpos[current_cpoollist]-=zc_min(combo_pool_listpos[current_cpoollist],comboaliaslist[j].w*z);
11172 }
11173 }
11174 goto domouse_donez;
11175 }
11176 }
11177 else if (draw_mode == dm_auto)
11178 {
11179 if (comboaliaslist[j].rect(x, y))
11180 {
11181 if (mouse_z < 0) //scroll down
11182 {
11183 combo_auto_listpos[current_cautolist] = zc_min(MAXAUTOCOMBOS - comboaliaslist[j].w * comboaliaslist[j].h,
11184 combo_auto_listpos[current_cautolist] + comboaliaslist[j].w * z);
11185 }
11186 else //scroll up
11187 {
11188 if (combo_auto_listpos[current_cautolist] > 0)
11189 {
11190 combo_auto_listpos[current_cautolist] -= zc_min(combo_auto_listpos[current_cautolist], comboaliaslist[j].w * z);
11191 }
11192 }
11193 goto domouse_donez;
11194 }
11195 }
11196 else
11197 {
11198 if(combolist[j].rect(x,y))
11199 {
11200 if(mouse_z<0) //scroll down
11201 {
11202 First[current_combolist] = zc_min(MAXCOMBOS-combolist[j].w*combolist[j].h,
11203 First[current_combolist] + combolist[j].w*z);
11204 }
11205 else //scroll up
11206 {
11207 if(First[current_combolist]>0)
11208 {
11209 First[current_combolist]-=zc_min(First[current_combolist],combolist[j].w*z);
11210 }
11211 }
11212 goto domouse_donez;
11213 }
11214 }
11215 }
11216
11217 z=abs(mouse_z);
11218
11219 if(real_mini.rect(x,y))
11220 {
11221 for(int32_t i=0; i<z; ++i)
11222 {
11223 if(mouse_z>0) onIncMap();
11224 else onDecMap();
11225 }
11226 goto domouse_donez;
11227 }
11228
11229 if(is_compact && compact_square_panels
11230 && squares_panel.rect(x,y))
11231 {
11232 cycle_compact_sqr(mouse_z < 0);
11233 goto domouse_donez;
11234 }
11235 domouse_donez:
11236 position_mouse_z(0);
11237 }
11238 font = tfont;
11239 active_visible_screen = nullptr;
11240 }
11241
11242 int32_t d_viewpal_proc(int32_t msg, DIALOG *d, int32_t c)
11243 {
11244 int32_t ret = d_bitmap_proc(msg, d, c);
11245 char* buf = (char*)d->dp2; //buffer to store the color code in
11246 DIALOG* d2 = (DIALOG*)d->dp3; //DIALOG* to update the text proc
11247 if(!buf)
11248 return ret;
11249 switch(msg)
11250 {
11251 case MSG_IDLE:
11252 case MSG_GOTMOUSE:
11253 case MSG_LOSTMOUSE:
11254 break;
11255 default:
11256 return ret;
11257 }
11258 char t[16];
11259 memcpy(t, buf, 16);
11260 int32_t x = gui_mouse_x() - d->x;
11261 int32_t y = gui_mouse_y() - d->y;
11262 if(msg != MSG_LOSTMOUSE && isinRect(x, y, 0, 0, d->w-1, d->h-1))
11263 {
11264 float palscale = 1.5;
11265 for(int32_t i = 0; i<256; ++i)
11266 if(isinRect(x,y,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale)))
11267 {
11268 sprintf(buf, "0x%02X (%03d) ", i, i); //Extra spaces to increase drawn width, so it draws the blank area
11269 break;
11270 }
11271 }
11272 else memset(buf, ' ', 15);
11273 if(strcmp(buf, t) && d2 && d2->proc == jwin_text_proc && d2->dp == d->dp2)
11274 object_message(d2, MSG_DRAW, 0);
11275 return ret;
11276 }
11277
11278 static DIALOG showpal_dlg[] =
11279 {
11280 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11281 { jwin_win_proc, 24, 68, 272, 119, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Palette", NULL, NULL },
11282 { jwin_frame_proc, 30, 76+16, 260, 68, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11283 { d_viewpal_proc, 32, 76+18, 256, 64, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11284 { jwin_text_proc, 32+8,76+18+66, 20, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
11285 { jwin_button_proc, 130, 144+18, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11286 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11287 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11288 };
11289
11290 int32_t onShowPal()
11291 {
11292 float palscale = 1.5;
11293
11294 BITMAP *palbmp = create_bitmap_ex(8,(int32_t)(256*palscale),(int32_t)(64*palscale));
11295
11296 if(!palbmp)
11297 return D_O_K;
11298 clear_to_color(palbmp,jwin_pal[jcBOX]); //If not cleared, random static appears between swatches! -E
11299 showpal_dlg[0].dp2=get_zc_font(font_lfont);
11300
11301 for(int32_t i=0; i<256; i++)
11302 rectfill(palbmp,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale),i);
11303 showpal_dlg[2].dp=(void *)palbmp;
11304 char buf[16] = {0};
11305 showpal_dlg[2].dp2=(void *)buf;
11306 showpal_dlg[2].dp3=(void *)&(showpal_dlg[3]);
11307 showpal_dlg[3].dp=(void *)buf;
11308 showpal_dlg[3].dp2=(void *)get_zc_font(font_deffont);
11309
11310 large_dialog(showpal_dlg);
11311 do_zqdialog(showpal_dlg,2);
11312 destroy_bitmap(palbmp);
11313 return D_O_K;
11314 }
11315
11316 static DIALOG csetfix_dlg[] =
11317 {
11318 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11319 { jwin_win_proc, 72, 80, 176+1, 96+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "CSet Fix", NULL, NULL },
11320 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11321 { jwin_radio_proc, 104+22, 108, 80+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full Screen", NULL, NULL },
11322 { jwin_radio_proc, 104+22, 118+2, 80+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Dungeon Floor", NULL, NULL },
11323 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
11324 { jwin_check_proc, 104+22, 128+4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "All Layers", NULL, NULL },
11325 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11326 { jwin_button_proc, 170, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11327 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11328 };
11329
11330 int32_t onCSetFix()
11331 {
11332 restore_mouse();
11333 csetfix_dlg[0].dp2=get_zc_font(font_lfont);
11334 int32_t s=2,x2=14,y2=9;
11335
11336 large_dialog(csetfix_dlg);
11337
11338 if(do_zqdialog(csetfix_dlg,-1)==6)
11339 {
11340 if(csetfix_dlg[2].flags&D_SELECTED)
11341 {
11342 s=0;
11343 x2=16;
11344 y2=11;
11345 }
11346
11347 if(csetfix_dlg[5].flags&D_SELECTED)
11348 {
11349 /*
11350 int32_t drawmap, drawscr;
11351 if (CurrentLayer==0)
11352 {
11353 drawmap=Map.getCurrMap();
11354 drawscr=Map.getCurrScr();
11355 }
11356 else
11357 {
11358 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
11359 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
11360 }
11361 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
11362 if(!draw_mapscr) return;
11363 saved=false;
11364 Map.Ugo();
11365
11366 if(!(draw_mapscr->valid&mVALID))
11367 {
11368 Map.CurrScr()->valid|=mVALID;
11369 draw_mapscr->valid|=mVALID;
11370 Map.setcolor(Color);
11371 }
11372 for(int32_t i=0; i<176; i++)
11373 {
11374 draw_mapscr->data[i]=Combo;
11375 draw_mapscr->cset[i]=CSet;
11376 }
11377 refresh(rMAP+rSCRMAP);
11378 */
11379 }
11380
11381 Map.StartListCommand();
11382 for(int32_t y=s; y<y2; y++)
11383 {
11384 for(int32_t x=s; x<x2; x++)
11385 {
11386 Map.DoSetComboCommand(Map.getCurrMap(), Map.getCurrScr(), (y<<4)+x, -1, CSet);
11387 }
11388 }
11389 Map.FinishListCommand();
11390
11391 refresh(rMAP);
11392 saved = false;
11393 }
11394
11395 return D_O_K;
11396 }
11397 static bool doAllSolidWater()
11398 {
11399 for(int32_t i=0; i < MAXCOMBOS; ++i)
11400 {
11401 if(combo_class_buf[combobuf[i].type].water!=0)
11402 {
11403 combobuf[i].walk |= 0x0F; //Solid
11404 }
11405 }
11406 return true;
11407 }
11408 static bool doNoSolidWater()
11409 {
11410 for(int32_t i=0; i < MAXCOMBOS; ++i)
11411 {
11412 if(combo_class_buf[combobuf[i].type].water!=0)
11413 {
11414 combobuf[i].walk &= ~0x0F; //Non-solid
11415 }
11416 }
11417 return true;
11418 }
11419 int32_t onWaterSolidity()
11420 {
11421 AlertFuncDialog("Water Conversion",
11422 "Forcibly set the solidity of all 'Liquid' combos in the quest?",
11423 ""
11424 ).add_buttons(2,
11425 { "Solid", "Non-Solid", "Cancel" },
11426 { doAllSolidWater, doNoSolidWater, nullptr }
11427 ).show();
11428 return D_O_K;
11429 }
11430
11431 static bool doAllEffectSquare()
11432 {
11433 for(int32_t i=0; i < MAXCOMBOS; ++i)
11434 {
11435 combobuf[i].walk |= 0xF0; //Effect
11436 }
11437 return true;
11438 }
11439 static bool doBlankEffectSquare()
11440 {
11441 for(int32_t i=0; i < MAXCOMBOS; ++i)
11442 {
11443 if(combobuf[i].is_blank(true))
11444 {
11445 combobuf[i].walk |= 0xF0; //Effect
11446 }
11447 }
11448 return true;
11449 }
11450
11451 int32_t onEffectFix()
11452 {
11453 AlertFuncDialog("Effect Square Conversion",
11454 "Forcibly fill the green effect square of all combos in the quest?",
11455 ""
11456 ).add_buttons(2,
11457 { "All", "Blank Only", "Cancel" },
11458 { doAllEffectSquare, doBlankEffectSquare, nullptr }
11459 ).show();
11460 return D_O_K;
11461 }
11462
11463 static bool clear_green_arrival_squares()
11464 {
11465 for(mapscr& scr : TheMaps)
11466 {
11467 if(!scr.valid) continue;
11468 scr.warparrivalx = 0;
11469 scr.warparrivaly = 0;
11470 }
11471 set_qr(qr_NOARRIVALPOINT, true);
11472 return true;
11473 }
11474
11475 static bool replace_green_arrival_squares()
11476 {
11477 // Check for conflicts first
11478 bool has_conflicts = false;
11479
11480 for(mapscr& scr : TheMaps)
11481 {
11482 if(!scr.valid) continue;
11483 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11484 if(scr.warpreturnx[0] || scr.warpreturny[0])
11485 {
11486 has_conflicts = true;
11487 break;
11488 }
11489 }
11490
11491 enum
11492 {
11493 NOT_ASKED = -1,
11494 MODE_FORCE, MODE_IGNORE, MODE_FIND_IGNORE, MODE_FIND_FORCE, MODE_CANCEL
11495 };
11496 int mode = NOT_ASKED;
11497
11498 if(has_conflicts)
11499 {
11500 AlertFuncDialog("Handle Conflicts",
11501 "Warp Square A is not available for all screens that have arrival squares."
11502 " How should this be handled? (See '?' for more info)",
11503 "Overwrite A: Replace the existing warp return square A with the position of the green arrival square"
11504 "\nIgnore: Do nothing if warp return square A exists"
11505 "\nFind Space or Ignore: Choose another, unused, square to set to the position of the green arrival square."
11506 " If none are unused, 'Ignore' instead."
11507 "\nFind Space or Overwrite: Choose another, unused square to set to the position of the green arrival square."
11508 " If none are unused, 'Overwrite A' instead."
11509 "\nCancel: Don't do anything"
11510 ).add_buttons(1,
11511 { "Overwrite A", "Ignore", "Find Space or Ignore", "Find Space or Overwrite A", "Cancel" },
11512 mode
11513 ).show();
11514 if(mode == NOT_ASKED || mode == MODE_CANCEL)
11515 return false;
11516 }
11517 for(mapscr& scr : TheMaps)
11518 {
11519 if(!scr.valid) continue;
11520 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11521 int indx = 0;
11522 if(scr.warpreturnx[0] || scr.warpreturny[0])
11523 {
11524 if(mode == MODE_IGNORE) continue; // Warp A not free, so ignore
11525 if(mode != MODE_FORCE)
11526 {
11527 for(int q = 1; q < 4; ++q)
11528 {
11529 if(scr.warpreturnx[q] || scr.warpreturny[q])
11530 continue;
11531 indx = q; // Use this warp, since it's free
11532 break;
11533 }
11534 if(indx == 0 && mode == MODE_FIND_IGNORE)
11535 continue; // Nothing free, so ignore
11536 }
11537 }
11538 scr.warpreturnx[indx] = scr.warparrivalx;
11539 scr.warpreturny[indx] = scr.warparrivaly;
11540 scr.warparrivalx = 0;
11541 scr.warparrivaly = 0;
11542 }
11543 set_qr(qr_NOARRIVALPOINT, true);
11544 return true;
11545 }
11546
11547 int32_t onRemoveOldArrivalSquare()
11548 {
11549 AlertFuncDialog("Arrival Square Removal",
11550 "Clear the old green 'Arrival' squares for the whole quest?"
11551 "\n(There will be no further confirmation, and this operation cannot be undone)",
11552 ""
11553 ).add_buttons(2,
11554 { "Replace With Blue Return Square", "Clear Completely", "Cancel" },
11555 { replace_green_arrival_squares, clear_green_arrival_squares, nullptr }
11556 ).show();
11557 return D_O_K;
11558 }
11559
11560 byte* getPalPointer(int32_t pal, int32_t cset)
11561 {
11562 if (pal < 0) return colordata + CSET(cset)*3;
11563 byte* ret = colordata + CSET(pal*pdLEVEL+poLEVEL)*3;
11564 switch(cset)
11565 {
11566 case 2: case 3: case 4:
11567 return ret + CSET(cset-2)*3;
11568 case 9:
11569 return ret + CSET(3)*3;
11570 case 1:
11571 return ret + CSET(13)*3;
11572 case 5:
11573 return ret + CSET(14)*3;
11574 case 7:
11575 return ret + CSET(15)*3;
11576 case 8:
11577 return ret + CSET(16)*3;
11578 }
11579 return NULL;
11580 }
11581
11582 void copyCSet(int32_t destpal, int32_t destcset, int32_t srcpal, int32_t srccset)
11583 {
11584 byte* dest = getPalPointer(destpal, destcset);
11585 byte* src = getPalPointer(srcpal, srccset);
11586 if (dest && src)
11587 {
11588 memcpy(dest, src, 16*3);
11589 }
11590 }
11591
11592 void setColorPalette(int32_t flags, int32_t lowpal, int32_t highpal)
11593 {
11594 for (auto q = lowpal; q <= highpal; ++q)
11595 {
11596 for (auto c = 0; c < 12; ++c)
11597 {
11598 if (!(flags&(1<<c))) continue;
11599 copyCSet(q, c, -1, c);
11600 }
11601 }
11602 }
11603
11604 void setPitDamage(int32_t flags, int32_t lowcombo, int32_t highcombo, int32_t damage)
11605 {
11606 for(int32_t i=lowcombo; i < highcombo; ++i)
11607 {
11608 if((combobuf[i].type == cPITFALL && (flags & (1<<0)))
11609 || (combobuf[i].type == cWATER && !(combobuf[i].usrflags & (1<<0)) && (flags & (1<<1)))
11610 || (combobuf[i].type == cWATER && (combobuf[i].usrflags & (1<<0)) && (flags & (1<<2))))
11611 {
11612 if ((combobuf[i].type != cPITFALL || (flags & (1<<9)) || !(combobuf[i].usrflags & (1<<0)))
11613 && ((flags & (1<<8)) || combobuf[i].attributes[0] == 0))
11614 combobuf[i].attributes[0] = damage*10000;
11615 }
11616 }
11617 }
11618
11619 static DIALOG template_dlg[] =
11620 {
11621 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11622 { jwin_win_proc, 72, 80, 176+1, 116+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "NES Dungeon Template", NULL, NULL },
11623 { d_comboframe_proc, 178, 122+3, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11624 { d_combo_proc, 180, 124+3, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11625 // { d_bitmap_proc, 180, 104, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11626 { jwin_radio_proc, 104+33, 128+3, 64+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Floor:", NULL, NULL },
11627 { jwin_radio_proc, 104+33, 148+3, 64+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "No Floor", NULL, NULL },
11628 { jwin_button_proc, 90, 172, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11629 { jwin_button_proc, 170, 172, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11630 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11631 { jwin_text_proc, 104, 102, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "This copies the contents of", NULL, NULL },
11632 { jwin_text_proc, 104, 112, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "screen 83 of the current map.", NULL, NULL },
11633 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11634 };
11635
11636 int32_t onTemplate()
11637 {
11638 static bool donethis=false;
11639
11640 if(!donethis||!(key[KEY_LSHIFT]||key[KEY_RSHIFT]))
11641 {
11642 template_dlg[2].d1=Combo;
11643 template_dlg[2].fg=CSet;
11644 donethis=true;
11645 }
11646
11647 restore_mouse();
11648
11649 if(Map.getCurrScr()==TEMPLATE)
11650 return D_O_K;
11651
11652 // BITMAP *floor_bmp = create_bitmap_ex(8,16,16);
11653 // if(!floor_bmp) return D_O_K;
11654 template_dlg[0].dp2=get_zc_font(font_lfont);
11655 // put_combo(floor_bmp,0,0,Combo,CSet,0,0);
11656 // template_dlg[2].dp=floor_bmp;
11657
11658 large_dialog(template_dlg);
11659
11660 if(do_zqdialog(template_dlg,-1)==5)
11661 {
11662 saved=false;
11663 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
11664 Map.DoTemplateCommand((template_dlg[3].flags==D_SELECTED) ? template_dlg[2].d1 : -1, template_dlg[2].fg, screen);
11665 refresh(rMAP+rSCRMAP);
11666 }
11667
11668 // destroy_bitmap(floor_bmp);
11669 return D_O_K;
11670 }
11671
11672 int32_t d_sel_scombo_proc(int32_t msg, DIALOG *d, int32_t c)
11673 {
11674 //these are here to bypass compiler warnings about unused arguments
11675 c=c;
11676
11677 switch(msg)
11678 {
11679 case MSG_CLICK:
11680 while(gui_mouse_b())
11681 {
11682 int32_t x = zc_min(zc_max(gui_mouse_x() - d->x,0)>>4, 15);
11683 int32_t y = zc_min(zc_max(gui_mouse_y() - d->y,0)&0xF0, 160);
11684
11685 if(x+y != d->d1)
11686 {
11687 d->d1 = x+y;
11688 custom_vsync();
11689 d_sel_scombo_proc(MSG_DRAW,d,0);
11690 }
11691 }
11692
11693 break;
11694
11695 case MSG_DRAW:
11696 {
11697 blit((BITMAP*)(d->dp),screen,0,0,d->x,d->y,d->w,d->h);
11698 int32_t x = d->x + (((d->d1)&15)<<4);
11699 int32_t y = d->y + ((d->d1)&0xF0);
11700 rect(screen,x,y,x+15,y+15,vc(15));
11701 }
11702 break;
11703 }
11704
11705 return D_O_K;
11706 }
11707
11708 static DIALOG cflag_dlg[] =
11709 {
11710 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
11711 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11712 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11713 12 { jwin_abclist_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11714 12 { jwin_button_proc, 70, 163, 51, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11715 12 { jwin_button_proc, 190, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11716 12 { jwin_button_proc, 130, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Help", NULL, NULL },
11717 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11718 };
11719
11720
11721 void questrev_help()
11722 {
11723 jwin_alert("Help","The revision number of your quest.",NULL,NULL,"O&K",NULL,'k',16,get_zc_font(font_lfont));
11724 }
11725
11726 void questminrev_help()
11727 {
11728 jwin_alert("Help","If a player's saved game was from a revision less than the minimum", "revision, they have to restart from the beginning.", "This is useful if you make major changes to your quest.","O&K",NULL,'k',16,get_zc_font(font_lfont));
11729 }
11730
11731 int32_t select_cflag(const char *prompt,int32_t flag)
11732 {
11733 cflag_dlg[0].dp=(void *)prompt;
11734 cflag_dlg[0].dp2=get_zc_font(font_lfont);
11735 GUI::ListData ld = GUI::ZCListData::mapflag(numericalFlags, true);
11736 ListData select_cflag_list = ld.getJWin(&font);
11737 int32_t index = ld.findIndex(flag);
11738 cflag_dlg[2].d1=index;
11739 cflag_dlg[2].dp=(void *) &select_cflag_list;
11740
11741 large_dialog(cflag_dlg);
11742
11743 int32_t ret;
11744
11745 do
11746 {
11747 ret=do_zqdialog(cflag_dlg,2);
11748
11749 if(ret==5)
11750 {
11751 cflag_help(ld.getValue(cflag_dlg[2].d1));
11752 }
11753 }
11754 while(ret==5);
11755
11756 if(ret==0||ret==4)
11757 {
11758 position_mouse_z(0);
11759 return -1;
11760 }
11761
11762 return ld.getValue(cflag_dlg[2].d1);
11763 }
11764
11765 int32_t select_flag(int32_t &f)
11766 {
11767 int32_t ret=select_cflag("Flag Type",f);
11768
11769 if(ret>=0)
11770 {
11771 f=ret;
11772 return true;
11773 }
11774
11775 return false;
11776 }
11777
11778 int32_t d_scombo_proc(int32_t msg,DIALOG *d,int32_t c)
11779 {
11780 //these are here to bypass compiler warnings about unused arguments
11781 c=c;
11782
11783 switch(msg)
11784 {
11785 case MSG_CLICK:
11786 {
11787 int32_t c2=d->d1;
11788 int32_t cs=d->fg;
11789 int32_t f=d->d2;
11790
11791 if(d->bg==1 || (CHECK_CTRL_CMD))
11792 {
11793 while(gui_mouse_b())
11794 {
11795 /* do nothing */
11796 rest(1);
11797 }
11798
11799 if(select_flag(f))
11800 {
11801 d->d2=f;
11802
11803 }
11804 }
11805 else if(key[KEY_LSHIFT])
11806 {
11807 if(gui_mouse_b()&1)
11808 {
11809 d->d1++;
11810
11811 if(d->d1>=MAXCOMBOS) d->d1=0;
11812 }
11813 else if(gui_mouse_b()&2)
11814 {
11815 d->d1--;
11816
11817 if(d->d1<0) d->d1=MAXCOMBOS-1;
11818 }
11819 }
11820 else if(key[KEY_RSHIFT])
11821 {
11822 if(gui_mouse_b()&1)
11823 {
11824 d->fg++;
11825
11826 if(d->fg>11) d->fg=0;
11827 }
11828 else if(gui_mouse_b()&2)
11829 {
11830 d->fg--;
11831
11832 if(d->fg<0) d->fg=11;
11833 }
11834 }
11835 else if(key[KEY_ALT])
11836 {
11837 if(gui_mouse_b()&1)
11838 {
11839 d->d1 = Combo;
11840 d->fg = CSet;
11841 }
11842 }
11843 else
11844 {
11845 if(select_combo_2(c2, cs))
11846 {
11847 d->d1=c2;
11848 d->fg=cs;
11849 }
11850 }
11851
11852 return D_REDRAW;
11853 }
11854 break;
11855
11856 case MSG_DRAW:
11857 d->w = 32;
11858 d->h = 32;
11859
11860 BITMAP *buf = create_bitmap_ex(8,16,16);
11861 BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h);
11862
11863 if(buf && bigbmp)
11864 {
11865 clear_bitmap(buf);
11866
11867 if(d->bg) //flags only
11868 {
11869 put_flag(buf,0,0,d->d2);
11870 }
11871 else if(d->d1)
11872 {
11873 putcombo(buf,0,0,d->d1,d->fg);
11874
11875 if(Flags&cFLAGS)
11876 put_flags(buf,0,0,d->d1,d->fg,cFLAGS,d->d2);
11877 }
11878
11879 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, d->w, d->h);
11880 destroy_bitmap(buf);
11881 blit(bigbmp,screen,0,0,d->x-1,d->y-1,d->w,d->h);
11882 destroy_bitmap(bigbmp);
11883 }
11884
11885
11886 /*BITMAP *buf = create_bitmap_ex(8,16,16);
11887 if(buf)
11888 {
11889 clear_bitmap(buf);
11890 if(d->d1)
11891 putcombo(buf,0,0,d->d1,d->fg);
11892
11893 blit(buf,screen,0,0,d->x,d->y,d->w,d->h);
11894 destroy_bitmap(buf);
11895 }*/
11896 break;
11897 }
11898
11899 return D_O_K;
11900 }
11901
11902 /*int32_t d_scombo2_proc(int32_t msg, DIALOG *d, int32_t c)
11903 {
11904 //these are here to bypass compiler warnings about unused arguments
11905 c=c;
11906
11907 switch(msg)
11908 {
11909 case MSG_CLICK:
11910 if (CHECK_CTRL_CMD)
11911 {
11912 select_scombo(d->d1);
11913 }
11914 else
11915 {
11916 select_scombo(d->d1);
11917 }
11918 d_scombo_proc(MSG_DRAW,d,0);
11919 break;
11920
11921
11922 case MSG_DRAW:
11923 BITMAP *buf = create_bitmap_ex(8,16,16);
11924 if(buf)
11925 {
11926 clear_bitmap(buf);
11927 Map.draw_secret2(buf,d->d1);
11928 blit(buf,screen,0,0,d->x,d->y,16,16);
11929 destroy_bitmap(buf);
11930 }
11931 break;
11932 }
11933
11934 return D_O_K;
11935 }*/
11936
11937 int32_t onSecretF();
11938
11939 static int32_t secret_burn_list[] =
11940 {
11941 // dialog control number
11942 4, 5, 6, 7, 48, 49, 50, 51, 92, 93, 94, 95, -1
11943 };
11944
11945 static int32_t secret_arrow_list[] =
11946 {
11947 // dialog control number
11948 8, 9, 10, 52, 53, 54, 96, 97, 98, -1
11949 };
11950
11951 static int32_t secret_bomb_list[] =
11952 {
11953 // dialog control number
11954 11, 12, 55, 56, 99, 100, -1
11955 };
11956
11957 static int32_t secret_boomerang_list[] =
11958 {
11959 // dialog control number
11960 13, 14, 15, 57, 58, 59, 101, 102, 103, -1
11961 };
11962
11963 static int32_t secret_magic_list[] =
11964 {
11965 // dialog control number
11966 16, 17, 60, 61, 104, 105, -1
11967 };
11968
11969 static int32_t secret_sword_list[] =
11970 {
11971 // dialog control number
11972 18, 19, 20, 21, 22, 23, 24, 25, 62, 63, 64, 65, 66, 67, 68, 69, 106, 107, 108, 109, 110, 111, 112, 113, -1
11973 };
11974
11975 static int32_t secret_misc_list[] =
11976 {
11977 // dialog control number
11978 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, -1
11979 };
11980
11981 static TABPANEL secret_tabs[] =
11982 {
11983 // (text)
11984 { (char *)"Burn", D_SELECTED, secret_burn_list, 0, NULL },
11985 { (char *)"Arrow", 0, secret_arrow_list, 0, NULL },
11986 { (char *)"Bomb", 0, secret_bomb_list, 0, NULL },
11987 { (char *)"Boomerang", 0, secret_boomerang_list, 0, NULL },
11988 { (char *)"Magic", 0, secret_magic_list, 0, NULL },
11989 { (char *)"Sword", 0, secret_sword_list, 0, NULL },
11990 { (char *)"Misc", 0, secret_misc_list, 0, NULL },
11991 { NULL, 0, NULL, 0, NULL }
11992 };
11993
11994 static DIALOG secret_dlg[] =
11995 {
11996 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
11997 { jwin_win_proc, 0, 0, 301, 212, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11998 { jwin_tab_proc, 6, 25, 289, 156, 0, 0, 0, 0, 0, 0, (void *) secret_tabs, NULL, (void *)secret_dlg },
11999 { jwin_button_proc, 80, 187, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12000 { jwin_button_proc, 160, 187, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12001 // 4
12002 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Fire", NULL, NULL },
12003 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Strong Fire", NULL, NULL },
12004 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Fire", NULL, NULL },
12005 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Divine Fire", NULL, NULL },
12006 //8
12007 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Arrow", NULL, NULL },
12008 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Silver Arrow", NULL, NULL },
12009 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Golden Arrow", NULL, NULL },
12010 //11
12011 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Bomb", NULL, NULL },
12012 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Super Bomb", NULL, NULL },
12013 //13
12014 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Boomerang", NULL, NULL },
12015 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Boomerang", NULL, NULL },
12016 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Fire Boomerang", NULL, NULL },
12017 //16
12018 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand Magic", NULL, NULL },
12019 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Magic", NULL, NULL },
12020 //18
12021 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword", NULL, NULL },
12022 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword", NULL, NULL },
12023 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword", NULL, NULL },
12024 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword", NULL, NULL },
12025 { jwin_text_proc, 160, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword Beam", NULL, NULL },
12026 { jwin_text_proc, 160, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword Beam", NULL, NULL },
12027 { jwin_text_proc, 160, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword Beam", NULL, NULL },
12028 { jwin_text_proc, 160, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword Beam", NULL, NULL },
12029 //26
12030 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Stairs", NULL, NULL },
12031 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Fireball", NULL, NULL },
12032 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hookshot", NULL, NULL },
12033 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand", NULL, NULL },
12034 { jwin_text_proc, 12, 141, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hammer", NULL, NULL },
12035 { jwin_text_proc, 12, 163, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Weapon", NULL, NULL },
12036 //32
12037 { jwin_ctext_proc, 235, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Flags 16-31", NULL, NULL },
12038 { jwin_text_proc, 87, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Secrets->Next (Flag only)", NULL, NULL },
12039 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 03", NULL, NULL },
12040 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 04", NULL, NULL },
12041 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 05", NULL, NULL },
12042 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 06", NULL, NULL },
12043 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 07", NULL, NULL },
12044 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 08", NULL, NULL },
12045 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 09", NULL, NULL },
12046 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 10", NULL, NULL },
12047 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 11", NULL, NULL },
12048 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 12", NULL, NULL },
12049 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 13", NULL, NULL },
12050 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 14", NULL, NULL },
12051 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 15", NULL, NULL },
12052 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 16", NULL, NULL },
12053 //48 (burn)
12054 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12055 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12056 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12057 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12058 //52 (arrow)
12059 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12060 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12061 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12062 //55 (bomb)
12063 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12064 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12065 //57 (boomerang)
12066 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12067 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12068 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12069 //60 (magic)
12070 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12071 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12072 //62 (sword)
12073 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12074 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12075 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12076 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12077 { jwin_frame_proc, 256, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12078 { jwin_frame_proc, 256, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12079 { jwin_frame_proc, 256, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12080 { jwin_frame_proc, 256, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12081 //70 (misc)
12082 { jwin_frame_proc, 63, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12083 { jwin_frame_proc, 63, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12084 { jwin_frame_proc, 63, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12085 { jwin_frame_proc, 63, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12086 { jwin_frame_proc, 63, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12087 { jwin_frame_proc, 63, 157, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12088 //76 (16-32)
12089 { jwin_frame_proc, 192, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12090 { jwin_frame_proc, 214, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12091 { jwin_frame_proc, 236, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12092 { jwin_frame_proc, 258, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12093 { jwin_frame_proc, 192, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12094 { jwin_frame_proc, 214, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12095 { jwin_frame_proc, 236, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12096 { jwin_frame_proc, 258, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12097 { jwin_frame_proc, 192, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12098 { jwin_frame_proc, 214, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12099 { jwin_frame_proc, 236, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12100 { jwin_frame_proc, 258, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12101 { jwin_frame_proc, 192, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12102 { jwin_frame_proc, 214, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12103 { jwin_frame_proc, 236, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12104 { jwin_frame_proc, 258, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12105
12106 //92 (burn)
12107 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12108 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12109 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12110 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12111 //96 (arrow)
12112 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12113 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12114 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12115 //99 (bomb)
12116 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12117 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12118 //101 (boomerang)
12119 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12120 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12121 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12122 //104 (magic)
12123 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12124 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12125 //106 (sword)
12126 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12127 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12128 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12129 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12130 { d_scombo_proc, 258, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12131 { d_scombo_proc, 258, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12132 { d_scombo_proc, 258, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12133 { d_scombo_proc, 258, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12134 //114 (misc)
12135 { d_scombo_proc, 65, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12136 { d_scombo_proc, 65, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12137 { d_scombo_proc, 65, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12138 { d_scombo_proc, 65, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12139 { d_scombo_proc, 65, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12140 { d_scombo_proc, 65, 159, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12141 //120 (16-32)
12142 { d_scombo_proc, 194, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12143 { d_scombo_proc, 216, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12144 { d_scombo_proc, 238, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12145 { d_scombo_proc, 260, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12146 { d_scombo_proc, 194, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12147 { d_scombo_proc, 216, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12148 { d_scombo_proc, 238, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12149 { d_scombo_proc, 260, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12150 { d_scombo_proc, 194, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12151 { d_scombo_proc, 216, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12152 { d_scombo_proc, 238, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12153 { d_scombo_proc, 260, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12154 { d_scombo_proc, 194, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12155 { d_scombo_proc, 216, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12156 { d_scombo_proc, 238, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12157 { d_scombo_proc, 260, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12158 //136 Secrets->Next
12159 { jwin_frame_proc, 158, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12160 { d_scombo_proc, 160, 49, 16, 16, 0, 1, 0, 0, 0, 0, NULL, NULL, NULL },
12161 //138
12162 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12163 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 'f', 0, 0, 0, (void *) onSecretF, NULL, NULL },
12164 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12165 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12166 };
12167
12168 int32_t onSecretF()
12169 {
12170 Flags^=cFLAGS;
12171 object_message(secret_dlg+1, MSG_DRAW, 0);
12172 return D_O_K;
12173 }
12174
12175
12176 int32_t onSecretCombo()
12177 {
12178 secret_dlg[0].dp2=get_zc_font(font_lfont);
12179
12180
12181 mapscr *s;
12182
12183 if(CurrentLayer==0)
12184 {
12185 s=Map.CurrScr();
12186 }
12187 else
12188 {
12189 // s=TheMaps[(Map.CurrScr()->layermap[CurrentLayer-1]-1)*MAPSCRS+(Map.CurrScr()->layerscreen[CurrentLayer-1])];
12190 s=Map.AbsoluteScr((Map.CurrScr()->layermap[CurrentLayer-1]-1), (Map.CurrScr()->layerscreen[CurrentLayer-1]));
12191 }
12192 if(!s) return D_O_K;
12193
12194 char secretcombonumstr[27];
12195 sprintf(secretcombonumstr,"Secret Combos for Layer %d", CurrentLayer);
12196 secret_dlg[0].dp = secretcombonumstr;
12197
12198 secret_dlg[92].d1 = s->secretcombo[sBCANDLE];
12199 secret_dlg[92].fg = s->secretcset[sBCANDLE];
12200 secret_dlg[92].d2 = s->secretflag[sBCANDLE];
12201
12202 secret_dlg[93].d1 = s->secretcombo[sRCANDLE];
12203 secret_dlg[93].fg = s->secretcset[sRCANDLE];
12204 secret_dlg[93].d2 = s->secretflag[sRCANDLE];
12205
12206 secret_dlg[94].d1 = s->secretcombo[sWANDFIRE];
12207 secret_dlg[94].fg = s->secretcset[sWANDFIRE];
12208 secret_dlg[94].d2 = s->secretflag[sWANDFIRE];
12209
12210 secret_dlg[95].d1 = s->secretcombo[sDIVINEFIRE];
12211 secret_dlg[95].fg = s->secretcset[sDIVINEFIRE];
12212 secret_dlg[95].d2 = s->secretflag[sDIVINEFIRE];
12213
12214 secret_dlg[96].d1 = s->secretcombo[sARROW];
12215 secret_dlg[96].fg = s->secretcset[sARROW];
12216 secret_dlg[96].d2 = s->secretflag[sARROW];
12217
12218 secret_dlg[97].d1 = s->secretcombo[sSARROW];
12219 secret_dlg[97].fg = s->secretcset[sSARROW];
12220 secret_dlg[97].d2 = s->secretflag[sSARROW];
12221
12222 secret_dlg[98].d1 = s->secretcombo[sGARROW];
12223 secret_dlg[98].fg = s->secretcset[sGARROW];
12224 secret_dlg[98].d2 = s->secretflag[sGARROW];
12225
12226 secret_dlg[99].d1 = s->secretcombo[sBOMB];
12227 secret_dlg[99].fg = s->secretcset[sBOMB];
12228 secret_dlg[99].d2 = s->secretflag[sBOMB];
12229
12230 secret_dlg[100].d1 = s->secretcombo[sSBOMB];
12231 secret_dlg[100].fg = s->secretcset[sSBOMB];
12232 secret_dlg[100].d2 = s->secretflag[sSBOMB];
12233
12234 for(int32_t i=0; i<3; i++)
12235 {
12236 secret_dlg[101+i].d1 = s->secretcombo[sBRANG+i];
12237 secret_dlg[101+i].fg = s->secretcset[sBRANG+i];
12238 secret_dlg[101+i].d2 = s->secretflag[sBRANG+i];
12239 }
12240
12241 for(int32_t i=0; i<2; i++)
12242 {
12243 secret_dlg[104+i].d1 = s->secretcombo[sWANDMAGIC+i];
12244 secret_dlg[104+i].fg = s->secretcset[sWANDMAGIC+i];
12245 secret_dlg[104+i].d2 = s->secretflag[sWANDMAGIC+i];
12246 }
12247
12248 for(int32_t i=0; i<8; i++)
12249 {
12250 secret_dlg[106+i].d1 = s->secretcombo[sSWORD+i];
12251 secret_dlg[106+i].fg = s->secretcset[sSWORD+i];
12252 secret_dlg[106+i].d2 = s->secretflag[sSWORD+i];
12253 }
12254
12255 secret_dlg[114].d1 = s->secretcombo[sSTAIRS];
12256 secret_dlg[114].fg = s->secretcset[sSTAIRS];
12257 secret_dlg[114].d2 = s->secretflag[sSTAIRS];
12258
12259 secret_dlg[115].d1 = s->secretcombo[sREFFIREBALL];
12260 secret_dlg[115].fg = s->secretcset[sREFFIREBALL];
12261 secret_dlg[115].d2 = s->secretflag[sREFFIREBALL];
12262
12263 for(int32_t i=0; i<4; i++)
12264 {
12265 secret_dlg[116+i].d1 = s->secretcombo[sHOOKSHOT+i];
12266 secret_dlg[116+i].fg = s->secretcset[sHOOKSHOT+i];
12267 secret_dlg[116+i].d2 = s->secretflag[sHOOKSHOT+i];
12268 }
12269
12270 for(int32_t i=0; i<16; i++)
12271 {
12272 secret_dlg[120+i].d1 = s->secretcombo[sSECRET01+i];
12273 secret_dlg[120+i].fg = s->secretcset[sSECRET01+i];
12274 secret_dlg[120+i].d2 = s->secretflag[sSECRET01+i];
12275 }
12276
12277 //Sec->Next doesn't have a combo/cset value associated
12278 secret_dlg[137].d1 = 0;
12279 secret_dlg[137].fg = 0;
12280 secret_dlg[137].d2 = s->secretflag[sSECNEXT];
12281
12282 large_dialog(secret_dlg,1.75);
12283
12284 for(int32_t q = 0; secret_dlg[q].proc != NULL; ++q)
12285 {
12286 if(secret_dlg[q].proc == jwin_frame_proc)
12287 secret_dlg[q].w = secret_dlg[q].h = 36;
12288 }
12289
12290 go();
12291
12292 if(do_zqdialog(secret_dlg,3) == 2)
12293 {
12294 saved = false;
12295 s->secretcombo[sBCANDLE] = secret_dlg[92].d1;
12296 s->secretcset[sBCANDLE] = secret_dlg[92].fg;
12297 s->secretflag[sBCANDLE] = secret_dlg[92].d2;
12298
12299 s->secretcombo[sRCANDLE] = secret_dlg[93].d1;
12300 s->secretcset[sRCANDLE] = secret_dlg[93].fg;
12301 s->secretflag[sRCANDLE] = secret_dlg[93].d2;
12302
12303 s->secretcombo[sWANDFIRE] = secret_dlg[94].d1;
12304 s->secretcset[sWANDFIRE] = secret_dlg[94].fg;
12305 s->secretflag[sWANDFIRE] = secret_dlg[94].d2;
12306
12307 s->secretcombo[sDIVINEFIRE] = secret_dlg[95].d1;
12308 s->secretcset[sDIVINEFIRE] = secret_dlg[95].fg;
12309 s->secretflag[sDIVINEFIRE] = secret_dlg[95].d2;
12310
12311 s->secretcombo[sARROW] = secret_dlg[96].d1;
12312 s->secretcset[sARROW] = secret_dlg[96].fg;
12313 s->secretflag[sARROW] = secret_dlg[96].d2;
12314
12315 s->secretcombo[sSARROW] = secret_dlg[97].d1;
12316 s->secretcset[sSARROW] = secret_dlg[97].fg;
12317 s->secretflag[sSARROW] = secret_dlg[97].d2;
12318
12319 s->secretcombo[sGARROW] = secret_dlg[98].d1;
12320 s->secretcset[sGARROW] = secret_dlg[98].fg;
12321 s->secretflag[sGARROW] = secret_dlg[98].d2;
12322
12323 s->secretcombo[sBOMB] = secret_dlg[99].d1;
12324 s->secretcset[sBOMB] = secret_dlg[99].fg;
12325 s->secretflag[sBOMB] = secret_dlg[99].d2;
12326
12327 s->secretcombo[sSBOMB] = secret_dlg[100].d1;
12328 s->secretcset[sSBOMB] = secret_dlg[100].fg;
12329 s->secretflag[sSBOMB] = secret_dlg[100].d2;
12330
12331 for(int32_t i=0; i<3; i++)
12332 {
12333 s->secretcombo[sBRANG+i] = secret_dlg[101+i].d1;
12334 s->secretcset[sBRANG+i] = secret_dlg[101+i].fg;
12335 s->secretflag[sBRANG+i] = secret_dlg[101+i].d2;
12336 }
12337
12338 for(int32_t i=0; i<2; i++)
12339 {
12340 s->secretcombo[sWANDMAGIC+i] = secret_dlg[104+i].d1;
12341 s->secretcset[sWANDMAGIC+i] = secret_dlg[104+i].fg;
12342 s->secretflag[sWANDMAGIC+i] = secret_dlg[104+i].d2;
12343 }
12344
12345 for(int32_t i=0; i<8; i++)
12346 {
12347 s->secretcombo[sSWORD+i] = secret_dlg[106+i].d1;
12348 s->secretcset[sSWORD+i] = secret_dlg[106+i].fg;
12349 s->secretflag[sSWORD+i] = secret_dlg[106+i].d2;
12350 }
12351
12352 s->secretcombo[sSTAIRS] = secret_dlg[114].d1;
12353 s->secretcset[sSTAIRS] = secret_dlg[114].fg;
12354 s->secretflag[sSTAIRS] = secret_dlg[114].d2;
12355
12356 s->secretcombo[sREFFIREBALL] = secret_dlg[115].d1;
12357 s->secretcset[sREFFIREBALL] = secret_dlg[115].fg;
12358 s->secretflag[sREFFIREBALL] = secret_dlg[115].d2;
12359
12360 for(int32_t i=0; i<4; i++)
12361 {
12362 s->secretcombo[sHOOKSHOT+i] = secret_dlg[116+i].d1;
12363 s->secretcset[sHOOKSHOT+i] = secret_dlg[116+i].fg;
12364 s->secretflag[sHOOKSHOT+i] = secret_dlg[116+i].d2;
12365 }
12366
12367 for(int32_t i=0; i<16; i++)
12368 {
12369 s->secretcombo[sSECRET01+i] = secret_dlg[120+i].d1;
12370 s->secretcset[sSECRET01+i] = secret_dlg[120+i].fg;
12371 s->secretflag[sSECRET01+i] = secret_dlg[120+i].d2;
12372 }
12373 s->secretflag[sSECNEXT] = secret_dlg[137].d2;
12374
12375 }
12376
12377 comeback();
12378 return D_O_K;
12379 }
12380
12381 static DIALOG under_dlg[] =
12382 {
12383 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
12384 { jwin_win_proc, 72, 60, 176+1,120+1,vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12385 { jwin_text_proc, 115, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "Current", NULL, NULL },
12386 { d_comboframe_proc, 122, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12387 { d_combo_proc, 124, 94, 16, 16, 0, 0, 0, D_NOCLICK, 0, 0, NULL, NULL, NULL },
12388 { jwin_text_proc, 184, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "New", NULL, NULL },
12389 { d_comboframe_proc, 182, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12390 { d_combo_proc, 184, 94, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12391 { jwin_button_proc, 90, 124, 61, 21, vc(14), vc(1), 's', D_EXIT, 0, 0, (void *) "&Set", NULL, NULL },
12392 { jwin_button_proc, 170, 124, 61, 21, vc(14), vc(1), 'c', D_EXIT, 0, 0, (void *) "&Cancel", NULL, NULL },
12393 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 'a', D_EXIT, 0, 0, (void *) "Set &All", NULL, NULL },
12394 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12395 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12396 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12397 };
12398
12399 int32_t onUnderCombo()
12400 {
12401 char titlebuf[64];
12402 sprintf(titlebuf, "Under Combo (Layer %d)", CurrentLayer);
12403 under_dlg[0].dp = titlebuf;
12404 under_dlg[0].dp2 = get_zc_font(font_lfont);
12405 mapscr* scr;
12406 if(CurrentLayer==0)
12407 {
12408 scr=Map.CurrScr();
12409 }
12410 else
12411 {
12412 auto map=Map.CurrScr()->layermap[CurrentLayer-1]-1;
12413 auto screen=Map.CurrScr()->layerscreen[CurrentLayer-1];
12414 scr = Map.AbsoluteScr(map,screen);
12415 }
12416 if(!scr) return D_O_K;
12417
12418 under_dlg[3].d1=scr->undercombo;
12419 under_dlg[3].fg=scr->undercset;
12420
12421 under_dlg[6].d1=Combo;
12422 under_dlg[6].fg=CSet;
12423
12424 large_dialog(under_dlg);
12425 // Doesn't place "New" and "Current" text too well
12426 under_dlg[1].x=342;
12427 under_dlg[4].x=438;
12428
12429 int32_t ret = do_zqdialog(under_dlg,-1);
12430
12431 if(ret==7)
12432 {
12433 saved=false;
12434 scr->undercombo = under_dlg[6].d1;
12435 scr->undercset = under_dlg[6].fg;
12436 }
12437
12438 if(ret==9 && jwin_alert("Confirm Overwrite","Set all Under Combos","on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
12439 {
12440 saved=false;
12441
12442 for(int32_t i=0; i<128; i++)
12443 {
12444 Map.Scr(i)->undercombo = under_dlg[6].d1;
12445 Map.Scr(i)->undercset = under_dlg[6].fg;
12446 }
12447 }
12448
12449 return D_O_K;
12450 }
12451
12452 static DIALOG list_dlg[] =
12453 {
12454 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
12455 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12456 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12457 12 { jwin_list_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12458 12 { jwin_button_proc, 90, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12459 12 { jwin_button_proc, 170, 163, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12460 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12461 };
12462
12463 /*
12464 typedef struct item_struct {
12465 char *s;
12466 int32_t i;
12467 } item_struct;
12468 */
12469 item_struct bii[MAXITEMS+1];
12470 int32_t bii_cnt=-1;
12471
12472 void build_bii_list(bool usenone)
12473 {
12474 int32_t start=bii_cnt=0;
12475
12476 if(usenone)
12477 {
12478 bii[0].s = (char *)"(None)";
12479 bii[0].i = -2;
12480 bii_cnt=start=1;
12481 }
12482
12483 for(int32_t i=0; i<MAXITEMS; i++)
12484 {
12485 bii[bii_cnt].s = item_string[i];
12486 bii[bii_cnt].i = i;
12487 ++bii_cnt;
12488 }
12489
12490 for(int32_t i=start; i<bii_cnt-1; i++)
12491 {
12492 for(int32_t j=i+1; j<bii_cnt; j++)
12493 {
12494 if(stricmp(bii[i].s,bii[j].s)>0 && strcmp(bii[j].s,""))
12495 {
12496 zc_swap(bii[i],bii[j]);
12497 }
12498 }
12499 }
12500 }
12501
12502
12503 const char *itemlist(int32_t index, int32_t *list_size)
12504 {
12505 if(index<0)
12506 {
12507 *list_size = bii_cnt;
12508 return NULL;
12509 }
12510
12511 return bii[index].s;
12512 }
12513 const char *itemlist_num(int32_t index, int32_t *list_size)
12514 {
12515 if(index<0)
12516 {
12517 *list_size = bii_cnt;
12518 return NULL;
12519 }
12520 static char biin_buf[64+6];
12521 if(bii[index].i < 0)
12522 return bii[index].s;
12523 sprintf(biin_buf, "%s (%03d)", bii[index].s, bii[index].i);
12524 return biin_buf;
12525 }
12526
12527 // disable items on dmaps stuff
12528 int32_t DI[MAXITEMS];
12529 int32_t nDI;
12530
12531 void initDI(int32_t index)
12532 {
12533 int32_t j=0;
12534
12535 for(int32_t i=0; i<MAXITEMS; i++)
12536 {
12537 int32_t index1=bii[i].i; // true index of item in dmap's DI list
12538
12539 if(DMaps[index].disableditems[index1])
12540 {
12541 DI[j]=i;
12542 j++;
12543 }
12544 }
12545
12546 nDI=j;
12547
12548 for(int32_t i=j; i<MAXITEMS; i++) DI[j]=0;
12549
12550 return;
12551 }
12552
12553 void insertDI(int32_t id, int32_t index)
12554 {
12555 int32_t trueid=bii[id].i;
12556 DMaps[index].disableditems[trueid] |= 1; //bit set
12557 initDI(index);
12558 return;
12559 }
12560
12561 void deleteDI(int32_t id, int32_t index)
12562 {
12563 int32_t i=DI[id];
12564 int32_t trueid=bii[i].i;
12565 DMaps[index].disableditems[trueid] &= (~1); // bit clear
12566 initDI(index);
12567 return;
12568 }
12569
12570 const char *DIlist(int32_t index, int32_t *list_size)
12571 {
12572 if(index<0)
12573 {
12574 *list_size = nDI;
12575 return NULL;
12576 }
12577
12578 int32_t i=DI[index];
12579 return bii[i].s;
12580
12581 }
12582
12583 weapon_struct biw[MAXWPNS];
12584 int32_t biw_cnt=-1;
12585
12586 void build_biw_list()
12587 {
12588 int32_t start=biw_cnt=0;
12589
12590 for(int32_t i=start; i<MAXWPNS; i++)
12591 {
12592 biw[biw_cnt].s = (char *)weapon_string[i];
12593 biw[biw_cnt].i = i;
12594 ++biw_cnt;
12595 }
12596
12597 for(int32_t i=start; i<biw_cnt-1; i++)
12598 {
12599 for(int32_t j=i+1; j<biw_cnt; j++)
12600 if(stricmp(biw[i].s,biw[j].s)>0 && strcmp(biw[j].s,""))
12601 zc_swap(biw[i],biw[j]);
12602 }
12603 }
12604
12605 const char *weaponlist(int32_t index, int32_t *list_size)
12606 {
12607 if(index<0)
12608 {
12609 *list_size = biw_cnt;
12610 return NULL;
12611 }
12612
12613 return biw[index].s;
12614 }
12615 const char *weaponlist_num(int32_t index, int32_t *list_size)
12616 {
12617 if(index<0)
12618 {
12619 *list_size = biw_cnt;
12620 return NULL;
12621 }
12622 static char biwn_buf[64+6];
12623 if(biw[index].i < 0)
12624 return biw[index].s;
12625 sprintf(biwn_buf, "%s (%03d)", biw[index].s, biw[index].i);
12626 return biwn_buf;
12627 }
12628 int32_t writeoneweapon(PACKFILE *f, int32_t index)
12629 {
12630 dword section_version=V_WEAPONS;
12631 int32_t zversion = ZELDA_VERSION;
12632 int32_t zbuild = VERSION_BUILD;
12633 int32_t iid = biw[index].i;
12634 al_trace("Writing Weapon Sprite .zwpnspr file for weapon id: %d\n", iid);
12635
12636 //section version info
12637 if(!p_iputl(zversion,f))
12638 {
12639 return 0;
12640 }
12641 if(!p_iputl(zbuild,f))
12642 {
12643 return 0;
12644 }
12645 if(!p_iputw(section_version,f))
12646 {
12647 return 0;
12648 }
12649
12650 if(!write_deprecated_section_cversion(section_version, f))
12651 {
12652 return 0;
12653 }
12654
12655 //weapon string
12656
12657 if(!pfwrite((char *)weapon_string[iid], 64, f))
12658 {
12659 return 0;
12660 }
12661
12662 if(!p_putc(wpnsbuf[iid].misc,f))
12663 {
12664 return 0;
12665 }
12666
12667 if(!p_putc(wpnsbuf[iid].csets,f))
12668 {
12669 return 0;
12670 }
12671
12672 if(!p_putc(wpnsbuf[iid].frames,f))
12673 {
12674 return 0;
12675 }
12676
12677 if(!p_putc(wpnsbuf[iid].speed,f))
12678 {
12679 return 0;
12680 }
12681
12682 if(!p_putc(wpnsbuf[iid].type,f))
12683 {
12684 return 0;
12685 }
12686
12687 if(!p_iputw(wpnsbuf[iid].script,f))
12688 {
12689 return 0;
12690 }
12691
12692 //2.55 starts here
12693 if(!p_iputl(wpnsbuf[iid].tile,f))
12694 {
12695 return 0;
12696 }
12697
12698 return 1;
12699 }
12700
12701
12702 int32_t readoneweapon(PACKFILE *f, int32_t index)
12703 {
12704 dword section_version = 0;
12705 int32_t zversion = 0;
12706 int32_t zbuild = 0;
12707 wpndata tempwpnspr;
12708 memset(&tempwpnspr, 0, sizeof(wpndata));
12709
12710
12711 //char dmapstring[64]={0};
12712 //section version info
12713 if(!p_igetl(&zversion,f))
12714 {
12715 return 0;
12716 }
12717 if(!p_igetl(&zbuild,f))
12718 {
12719 return 0;
12720 }
12721 if(!p_igetw(&section_version,f))
12722 {
12723 return 0;
12724 }
12725 if(!read_deprecated_section_cversion(f))
12726 {
12727 return 0;
12728 }
12729 al_trace("readoneweapon section_version: %d\n", section_version);
12730
12731 if ( zversion > ZELDA_VERSION )
12732 {
12733 al_trace("Cannot read .zwpnspr packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
12734 return 0;
12735 }
12736
12737 else if ( ( section_version > V_WEAPONS ) )
12738 {
12739 al_trace("Cannot read .zwpnspr packfile made using V_WEAPONS (%d)\n", section_version);
12740 return 0;
12741
12742 }
12743 else
12744 {
12745 al_trace("Reading a .zwpnspr packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
12746 }
12747
12748 char tmp_wpn_name[64];
12749 memset(tmp_wpn_name,0,64);
12750 if(!pfread(&tmp_wpn_name, 64, f))
12751 {
12752 return 0;
12753 }
12754
12755 word oldtile = 0;
12756 if(section_version < 8)
12757 if(!p_igetw(&oldtile,f))
12758 return 0;
12759
12760 if(!p_getc(&tempwpnspr.misc,f))
12761 {
12762 return 0;
12763 }
12764
12765 if(!p_getc(&tempwpnspr.csets,f))
12766 {
12767 return 0;
12768 }
12769
12770 if(!p_getc(&tempwpnspr.frames,f))
12771 {
12772 return 0;
12773 }
12774
12775 if(!p_getc(&tempwpnspr.speed,f))
12776 {
12777 return 0;
12778 }
12779
12780 if(!p_getc(&tempwpnspr.type,f))
12781 {
12782 return 0;
12783 }
12784
12785 if(!p_igetw(&tempwpnspr.script,f))
12786 {
12787 return 0;
12788 }
12789
12790 //2.55 starts here
12791 if ( zversion >= 0x255 )
12792 {
12793 if ( section_version >= 7 )
12794 {
12795 if(!p_igetl(&tempwpnspr.tile,f))
12796 {
12797 return 0;
12798 }
12799 }
12800 }
12801 if ( zversion < 0x255 )
12802 {
12803 tempwpnspr.tile = oldtile;
12804 }
12805 ::memcpy( &(wpnsbuf[biw[index].i]),&tempwpnspr, sizeof(wpndata));
12806 ::memcpy(weapon_string[biw[index].i], tmp_wpn_name, 64);
12807
12808 return 1;
12809 }
12810
12811 static int32_t seldata_copy;
12812 static void (*seldata_paste_func)(int32_t, int32_t);
12813
12814 void seldata_rclick_func(int32_t index, int32_t x, int32_t y)
12815 {
12816 NewMenu rcmenu {
12817 { "&Copy", [&](){seldata_copy = index;} },
12818 { "Paste", "&v", [&]()
12819 {
12820 seldata_paste_func(seldata_copy, index);
12821 saved = false;
12822 }, 0, seldata_copy < 0 },
12823 };
12824 rcmenu.pop(x, y);
12825 }
12826
12827 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12828 {
12829 if(proc==NULL)
12830 return -1;
12831
12832 list_dlg[0].dp=(void *)prompt;
12833 list_dlg[0].dp2=title_font;
12834 list_dlg[2].d1=index;
12835 ListData select_list(proc, &font);
12836 list_dlg[2].dp=(void *) &select_list;
12837
12838 large_dialog(list_dlg);
12839
12840 seldata_copy=-1;
12841 seldata_paste_func=copyFunc;
12842 if(copyFunc)
12843 {
12844 list_dlg[2].flags|=D_USER<<1;
12845 list_dlg[2].dp3=(void*)seldata_rclick_func;
12846 }
12847 else
12848 {
12849 list_dlg[2].flags&=~(D_USER<<1);
12850 list_dlg[2].dp3=0;
12851 }
12852
12853 int32_t ret=do_zqdialog(list_dlg,2);
12854
12855 if(ret==0||ret==4)
12856 {
12857 position_mouse_z(0);
12858 return -1;
12859 }
12860
12861 return list_dlg[2].d1;
12862 }
12863
12864 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), const char *b1, const char *b2, FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12865 {
12866 if(proc==NULL)
12867 return -1;
12868
12869 list_dlg[0].dp=(void *)prompt;
12870 list_dlg[0].dp2=title_font;
12871 list_dlg[2].d1=index;
12872 ListData select_data_list(proc, &font);
12873 list_dlg[2].dp=(void *) &select_data_list;
12874 list_dlg[3].dp=(void *)b1;
12875 list_dlg[4].dp=(void *)b2;
12876
12877 large_dialog(list_dlg);
12878
12879 seldata_copy=-1;
12880 seldata_paste_func=copyFunc;
12881 if(copyFunc)
12882 {
12883 list_dlg[2].flags|=D_USER<<1;
12884 list_dlg[2].dp3=(void*)seldata_rclick_func;
12885 }
12886 else
12887 {
12888 list_dlg[2].flags&=~(D_USER<<1);
12889 list_dlg[2].dp3=0;
12890 }
12891
12892 int32_t ret = do_zqdialog(list_dlg,2);
12893 list_dlg[3].dp=(void *) "OK";
12894 list_dlg[4].dp=(void *) "Cancel";
12895
12896 if(ret==0||ret==4)
12897 {
12898 position_mouse_z(0);
12899 return -1;
12900 }
12901
12902 position_mouse_z(0);
12903 return list_dlg[2].d1;
12904 }
12905
12906 static char sfx_str_buf[42];
12907
12908 const char *sfxlist(int32_t index, int32_t *list_size)
12909 {
12910 if(index>=0)
12911 {
12912 bound(index,0,WAV_COUNT-1);
12913 sprintf(sfx_str_buf,"%d: %s",index, index ? sfx_string[index] : "(None)");
12914 return sfx_str_buf;
12915 }
12916
12917 *list_size=WAV_COUNT;
12918 return NULL;
12919 }
12920
12921 12 static ListData sfx_list(sfxlist, &font);
12922
12923 const char *screenscriptdroplist(int32_t index, int32_t *list_size)
12924 {
12925 if(index<0)
12926 {
12927 *list_size = biscreens_cnt;
12928 return NULL;
12929 }
12930
12931 return biscreens[index].first.c_str();
12932 }
12933
12934 //droplist like the dialog proc, naming scheme for this stuff is awful...
12935 12 static ListData screenscript_list(screenscriptdroplist, &a4fonts[font_pfont]);
12936
12937 int32_t onScreenScript()
12938 {
12939 call_screendata_dialog(7);
12940 return D_O_K;
12941 }
12942
12943 int32_t onScrData()
12944 {
12945 restore_mouse();
12946 call_screendata_dialog();
12947 return D_O_K;
12948 }
12949
12950 const char *roomslist(int32_t index, int32_t *list_size)
12951 {
12952 if(index>=0)
12953 {
12954 if(index>=MAXROOMTYPES)
12955 index=MAXROOMTYPES-1;
12956
12957 return roomtype_string[index];
12958 }
12959
12960 *list_size=MAXROOMTYPES;
12961 return NULL;
12962 }
12963
12964 static char number_str_buf[MIDI_TRACK_BUFFER_SIZE];
12965 int32_t number_list_size=1;
12966 bool number_list_zero=false;
12967
12968 const char *numberlist(int32_t index, int32_t *list_size)
12969 {
12970 if(index>=0)
12971 {
12972 bound(index,0,number_list_size-1);
12973 sprintf(number_str_buf,"%d",index+(number_list_zero?0:1));
12974 return number_str_buf;
12975 }
12976
12977 *list_size=number_list_size;
12978 return NULL;
12979 }
12980
12981 static char dmap_str_buf[37];
12982 int32_t dmap_list_size=MAXDMAPS;
12983 bool dmap_list_zero=true;
12984
12985 const char *dmaplist(int32_t index, int32_t *list_size)
12986 {
12987 if(index>=0)
12988 {
12989 bound(index,0,dmap_list_size-1);
12990 sprintf(dmap_str_buf,"%3d-%s",index+(dmap_list_zero?0:1), DMaps[index].name);
12991 return dmap_str_buf;
12992 }
12993
12994 *list_size=dmap_list_size;
12995 return NULL;
12996 }
12997
12998 char *hexnumlist(int32_t index, int32_t *list_size)
12999 {
13000 if(index>=0)
13001 {
13002 bound(index,0,number_list_size-1);
13003 sprintf(number_str_buf,"%X",index+(number_list_zero?0:1));
13004 return number_str_buf;
13005 }
13006
13007 *list_size=number_list_size;
13008 return NULL;
13009 }
13010
13011 const char *maplist(int32_t index, int32_t *list_size)
13012 {
13013 if(index>=0)
13014 {
13015 bound(index,0,MAXMAPS-1);
13016 sprintf(number_str_buf,"%d",index+1);
13017 return number_str_buf;
13018 }
13019
13020 *list_size=MAXMAPS;
13021 return NULL;
13022 }
13023
13024 const char *gotomaplist(int32_t index, int32_t *list_size)
13025 {
13026 if(index>=0)
13027 {
13028 bound(index,0,map_count-1);
13029 sprintf(number_str_buf,"%d",index+1);
13030 return number_str_buf;
13031 }
13032
13033 *list_size = map_count;
13034 return NULL;
13035 }
13036
13037 const char *midilist(int32_t index, int32_t *list_size)
13038 {
13039 if(index>=0)
13040
13041 {
13042 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13043 return midi_string[index];
13044 }
13045
13046 *list_size=MAXCUSTOMMIDIS_ZQ;
13047 return NULL;
13048 }
13049
13050 const char *custommidilist(int32_t index, int32_t *list_size)
13051 {
13052 if(index>=0)
13053 {
13054 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13055 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),customtunes[index].data?customtunes[index].title:"(Empty)");
13056 return number_str_buf;
13057 }
13058
13059 *list_size=number_list_size;
13060 return NULL;
13061 }
13062
13063 const char *enhancedmusiclist(int32_t index, int32_t *list_size)
13064 {
13065 index=index; //this is here to prevent unused parameter warnings
13066 list_size=list_size; //this is here to prevent unused parameter warnings
13067 /*if(index>=0)
13068 {
13069 bound(index,0,MAXMUSIC-1);
13070 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),enhancedMusic[index].filename[0]?enhancedMusic[index].title:"(Empty)" );
13071 return number_str_buf;
13072 }
13073 *list_size=number_list_size;*/
13074 return NULL;
13075 }
13076
13077
13078 const char *levelnumlist(int32_t index, int32_t *list_size)
13079 {
13080 if(index>=0)
13081 {
13082 bound(index,0,0xFFF);
13083 sprintf(number_str_buf,"%.3X - %s",index,palnames[index]);
13084 return number_str_buf;
13085 }
13086
13087 *list_size=MAXLEVELS;
13088 return NULL;
13089 }
13090
13091 static char shop_str_buf[40];
13092 int32_t shop_list_size=1;
13093
13094 const char *shoplist(int32_t index, int32_t *list_size)
13095 {
13096 if(index>=0)
13097 {
13098 bound(index,0,shop_list_size-1);
13099 sprintf(shop_str_buf,"%3d: %s",index,QMisc.shop[index].name);
13100 return shop_str_buf;
13101 }
13102
13103 *list_size=shop_list_size;
13104 return NULL;
13105 }
13106
13107 static char bottle_str_buf[40];
13108 int32_t bottle_list_size=1;
13109
13110 const char *bottlelist(int32_t index, int32_t *list_size)
13111 {
13112 if(index>=0)
13113 {
13114 bound(index,0,bottle_list_size-1);
13115 sprintf(bottle_str_buf,"%2d: %s",index+1,QMisc.bottle_types[index].name);
13116 return bottle_str_buf;
13117 }
13118
13119 *list_size=bottle_list_size;
13120 return NULL;
13121 }
13122
13123 static char bottleshop_str_buf[40];
13124 int32_t bottleshop_list_size=1;
13125
13126 const char *bottleshoplist(int32_t index, int32_t *list_size)
13127 {
13128 if(index>=0)
13129 {
13130 bound(index,0,bottleshop_list_size-1);
13131 sprintf(bottleshop_str_buf,"%3d: %s",index,QMisc.bottle_shop_types[index].name);
13132 return bottleshop_str_buf;
13133 }
13134
13135 *list_size=bottleshop_list_size;
13136 return NULL;
13137 }
13138
13139 static char info_str_buf[40];
13140 int32_t info_list_size=1;
13141
13142 const char *infolist(int32_t index, int32_t *list_size)
13143 {
13144 if(index>=0)
13145 {
13146 bound(index,0,info_list_size-1);
13147 sprintf(info_str_buf,"%3d: %s",index,QMisc.info[index].name);
13148 return info_str_buf;
13149 }
13150
13151 *list_size=info_list_size;
13152 return NULL;
13153 }
13154
13155 bool mapcount_will_affect_layers(word newmapcount)
13156 {
13157 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13158 {
13159 mapscr *layerchecker=&TheMaps[i];
13160
13161 for(int32_t j=0; j<6; j++)
13162 {
13163 if(layerchecker->layermap[j]>(newmapcount))
13164 {
13165 return true;
13166 }
13167 }
13168 }
13169 return false;
13170 }
13171
13172 void update_map_count(word newmapcount)
13173 {
13174 if(map_count == newmapcount) return;
13175 saved = false;
13176 setMapCount2(newmapcount);
13177 //Prevent the nine 'last mapscreen' buttons from pointing to invlid locations
13178 //if the user reduces the mapcount. -Z ( 23rd September, 2019 )
13179 for ( int32_t q = 0; q < 9; q++ )
13180 {
13181 map_page[q].map = ( map_page[q].map > newmapcount-1 ) ? newmapcount-1 : map_page[q].map;
13182 }
13183 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13184 {
13185 fix_layers(&TheMaps[i], false);
13186 }
13187
13188 refresh(rMAP+rSCRMAP+rMENU);
13189 }
13190
13191 int32_t onGotoMap()
13192 {
13193 int32_t ret = select_data("Goto Map",Map.getCurrMap(),gotomaplist,get_zc_font(font_lfont));
13194
13195 if(ret >= 0)
13196 {
13197 int32_t m=Map.getCurrMap();
13198 Map.setCurrMap(ret);
13199 }
13200
13201 refresh(rALL);
13202 return D_O_K;
13203 }
13204
13205 int32_t onFlags()
13206 {
13207 restore_mouse();
13208 int32_t ret=select_cflag("Select Combo Flag",Flag);
13209 position_mouse_z(0);
13210
13211 if(ret>=0)
13212 {
13213 Flag=ret;
13214 refresh(rMENU);
13215 doflags();
13216 }
13217
13218 return D_O_K;
13219 }
13220
13221 static DIALOG usedcombo_list_dlg[] =
13222 {
13223 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13224 12 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combos Used", NULL, NULL },
13225 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13226 12 { jwin_textbox_proc, 72-12, 60+4, 176+24+1, 92+4, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
13227 12 { jwin_button_proc, 130, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13228 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13229 };
13230
13231
13232
13233 int32_t onUsedCombos()
13234 {
13235 restore_mouse();
13236 usedcombo_list_dlg[0].dp2=get_zc_font(font_lfont);
13237
13238 int32_t usedcombos[7][300][2];
13239 char combolist_text[65536];
13240 char temptext[80];
13241
13242 int32_t drawmap=Map.getCurrMap();
13243 int32_t drawscr=Map.getCurrScr();
13244 int32_t counter[7];
13245
13246 for(int32_t layer=0; layer<7; ++layer)
13247 {
13248 counter[layer]=0;
13249
13250 if(layer==0)
13251 {
13252 drawmap=Map.getCurrMap();
13253 drawscr=Map.getCurrScr();
13254 }
13255 else
13256 {
13257 drawmap=Map.CurrScr()->layermap[layer-1]-1;
13258 drawscr=Map.CurrScr()->layerscreen[layer-1];
13259 }
13260 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
13261 if(!draw_mapscr) continue;
13262
13263 usedcombos[layer][0][0]=draw_mapscr->data[0];
13264 usedcombos[layer][0][1]=1;
13265 counter[layer]=1;
13266
13267 for(int32_t i=1; i<176; ++i)
13268 {
13269 bool used=false;
13270
13271 for(int32_t j=0; j<counter[layer]; ++j)
13272 {
13273 if(usedcombos[layer][j][0]==draw_mapscr->data[i])
13274 {
13275 ++usedcombos[layer][j][1];
13276 used=true;
13277 break;
13278 }
13279 }
13280
13281 if(!used)
13282 {
13283 usedcombos[layer][counter[layer]][0]=draw_mapscr->data[i];
13284 usedcombos[layer][counter[layer]][1]=1;
13285 ++counter[layer];
13286 }
13287 }
13288
13289 for(int32_t i=0; i<counter[layer]-1; i++)
13290 {
13291 for(int32_t j=i+1; j<counter[layer]; j++)
13292 {
13293 if(usedcombos[layer][i][0]>usedcombos[layer][j][0])
13294 {
13295 zc_swap(usedcombos[layer][i][0],usedcombos[layer][j][0]);
13296 zc_swap(usedcombos[layer][i][1],usedcombos[layer][j][1]);
13297 }
13298 }
13299 }
13300 }
13301
13302 sprintf(combolist_text, " ");
13303
13304 for(int32_t layer=0; layer<7; ++layer)
13305 {
13306 if(counter[layer]>0)
13307 {
13308 if(layer>0)
13309 {
13310 strcat(combolist_text, "\n");
13311 }
13312
13313 sprintf(temptext, "Combos on layer %d\n-----------------\n", layer);
13314 strcat(combolist_text, temptext);
13315
13316 for(int32_t i=0; i<counter[layer]; i++)
13317 {
13318 if((i<counter[layer]-1) && (((usedcombos[layer][i][1]==usedcombos[layer][i+1][1]&&(usedcombos[layer][i][0]+1==usedcombos[layer][i+1][0])) && ((i==0) || ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))))
13319 {
13320 sprintf(temptext, "%5d ", usedcombos[layer][i][0]);
13321 strcat(combolist_text, temptext);
13322 }
13323 else if(((i>0) && (((usedcombos[layer][i][1]==usedcombos[layer][i-1][1])&&((usedcombos[layer][i][0]-1==usedcombos[layer][i-1][0]))) && ((i==counter[layer]-1) || ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0])))))))
13324 {
13325 sprintf(temptext, "- %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13326 strcat(combolist_text, temptext);
13327 }
13328 else if(((i==0) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))))||
13329 ((i==counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0]))))||
13330 ((i>0) && (i<counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))
13331 {
13332 sprintf(temptext, " %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13333 strcat(combolist_text, temptext);
13334 }
13335 }
13336 }
13337 }
13338
13339 strcat(combolist_text, "\n");
13340 usedcombo_list_dlg[2].dp=combolist_text;
13341 usedcombo_list_dlg[2].d2=0;
13342
13343 large_dialog(usedcombo_list_dlg);
13344
13345 do_zqdialog(usedcombo_list_dlg,2);
13346 position_mouse_z(0);
13347 return D_O_K;
13348 }
13349
13350 int32_t onItem()
13351 {
13352 restore_mouse();
13353 int32_t exit_status;
13354 int32_t current_item=Map.CurrScr()->hasitem != 0 ? Map.CurrScr()->item : -1;
13355
13356 ItemListerDialog(current_item,true).show();
13357 if(current_item != lister_sel_val)
13358 {
13359 if(lister_sel_val>=0)
13360 {
13361 saved = false;
13362 Map.CurrScr()->item = lister_sel_val;
13363 Map.CurrScr()->hasitem = true;
13364 }
13365 else
13366 {
13367 saved = false;
13368 Map.CurrScr()->hasitem = false;
13369 }
13370 }
13371
13372 refresh(rMAP+rMENU);
13373 return D_O_K;
13374 }
13375
13376 void call_room_dlg(mapscr* scr);
13377 int32_t onRoom()
13378 {
13379 restore_mouse();
13380 auto* scr = Map.CurrScr();
13381 call_room_dlg(scr);
13382
13383 refresh(rMAP+rMENU);
13384 return D_O_K;
13385 }
13386
13387 int32_t onEndString()
13388 {
13389 int32_t ret=select_data("Select Ending String",QMisc.endstring,msgslist,get_zc_font(font_lfont));
13390
13391 if(ret>=0)
13392 {
13393 saved=false;
13394 QMisc.endstring=msglistcache[ret];
13395 }
13396
13397 refresh(rMENU);
13398 return D_O_K;
13399 }
13400
13401 12 static ListData levelnum_list(levelnumlist, &font);
13402
13403 static DIALOG screen_pal_dlg[] =
13404 {
13405 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13406 12 { jwin_win_proc, 60-12, 40, 200-16, 96, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Palette", NULL, NULL },
13407 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13408 12 { jwin_droplist_proc, 72-12, 84+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &levelnum_list, NULL, NULL },
13409 12 { jwin_button_proc, 70, 111, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13410 12 { jwin_button_proc, 150, 111, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13411 12 { jwin_text_proc, 72-12, 60+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Note: This does not affect how the", NULL, NULL },
13412 12 { jwin_text_proc, 72-12, 72+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "room will be displayed in-game!", NULL, NULL },
13413 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13414 };
13415 // return list_dlg[2].d1;
13416
13417 int32_t onScreenPalette()
13418 {
13419 restore_mouse();
13420 screen_pal_dlg[0].dp2=get_zc_font(font_lfont);
13421 auto oldcol = screen_pal_dlg[2].d1 = Map.getcolor();
13422
13423 large_dialog(screen_pal_dlg);
13424 auto old_valid = Map.CurrScr()->valid;
13425 pause_dlg_tint(true);
13426 zq_set_screen_never_freeze(true);
13427 while(true)
13428 {
13429 auto ret = do_zqdialog(screen_pal_dlg,2);
13430 if(ret == 2)
13431 {
13432 Map.setcolor(screen_pal_dlg[2].d1);
13433 refresh(rALL);
13434 }
13435 else
13436 {
13437 if(ret == 3)
13438 {
13439 if(screen_pal_dlg[2].d1 != oldcol)
13440 saved=false;
13441 Map.setcolor(screen_pal_dlg[2].d1);
13442 }
13443 else
13444 {
13445 Map.setcolor(oldcol);
13446 Map.CurrScr()->valid = old_valid;
13447 }
13448 refresh(rALL);
13449 break;
13450 }
13451 }
13452 pause_dlg_tint(false);
13453 zq_set_screen_never_freeze(false);
13454
13455 rebuild_trans_table();
13456
13457 return D_O_K;
13458 }
13459
13460 int32_t onDecScrPal()
13461 {
13462 if(DisableLPalShortcuts)
13463 {
13464 lpal_dsa();
13465 return D_O_K;
13466 }
13467 restore_mouse();
13468 int32_t c=Map.getcolor();
13469 c+=511;
13470 c=c%512;
13471 Map.setcolor(c);
13472 refresh(rALL);
13473 saved = false;
13474 return D_O_K;
13475 }
13476
13477 int32_t onIncScrPal()
13478 {
13479 if(DisableLPalShortcuts)
13480 {
13481 lpal_dsa();
13482 return D_O_K;
13483 }
13484 restore_mouse();
13485 int32_t c=Map.getcolor();
13486 c+=1;
13487 c=c%512;
13488 Map.setcolor(c);
13489 refresh(rALL);
13490 saved = false;
13491 return D_O_K;
13492 }
13493
13494 int32_t PalWrap(int32_t kX, int32_t const kLowerBound, int32_t const kUpperBound)
13495 {
13496 int32_t range_size = kUpperBound - kLowerBound + 1;
13497
13498 if (kX < kLowerBound)
13499 kX += range_size * ((kLowerBound - kX) / range_size + 1);
13500
13501 return kLowerBound + (kX - kLowerBound) % range_size;
13502 }
13503
13504 int32_t onDecScrPal16()
13505 {
13506 if(DisableLPalShortcuts)
13507 {
13508 lpal_dsa();
13509 return D_O_K;
13510 }
13511 restore_mouse();
13512 int32_t c=Map.getcolor();
13513
13514 c = PalWrap( ( c-0x10 ), 0, 511 );
13515
13516 Map.setcolor(c);
13517 refresh(rALL);
13518 saved = false;
13519 return D_O_K;
13520 }
13521
13522 int32_t onIncScrPal16()
13523 {
13524 if(DisableLPalShortcuts)
13525 {
13526 lpal_dsa();
13527 return D_O_K;
13528 }
13529 restore_mouse();
13530 int32_t c=Map.getcolor();
13531
13532 c = PalWrap( ( c+0x10 ), 0, 511 );
13533 Map.setcolor(c);
13534 refresh(rALL);
13535 saved = false;
13536 return D_O_K;
13537 }
13538
13539 int32_t onZoomIn()
13540 {
13541 change_mapscr_zoom(-1);
13542 return D_O_K;
13543 }
13544
13545 int32_t onZoomOut()
13546 {
13547 change_mapscr_zoom(1);
13548 return D_O_K;
13549 }
13550
13551 int32_t d_ndroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13552 {
13553 int32_t ret = jwin_droplist_proc(msg,d,c);
13554
13555 // The only place this proc is used is in the info type editor.
13556 // If it's ever used anywhere else, this will probably need to be changed.
13557 // Maybe add a flag for it or something.
13558 int32_t msgID=msg_at_pos(d->d1);
13559
13560 switch(msg)
13561 {
13562 case MSG_DRAW:
13563 case MSG_CHAR:
13564 case MSG_CLICK:
13565 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",msgID);
13566 }
13567
13568 return ret;
13569 }
13570
13571 int32_t d_idroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13572 {
13573 int32_t ret = jwin_droplist_proc(msg,d,c);
13574
13575 switch(msg)
13576 {
13577 case MSG_DRAW:
13578 case MSG_CHAR:
13579 case MSG_CLICK:
13580 int32_t tile = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].tile : 0;
13581 int32_t cset = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].csets&15 : 0;
13582 int32_t x = d->x + d->w + 4;
13583 int32_t y = d->y - 8;
13584 int32_t w = 32;
13585 int32_t h = 32;
13586
13587 BITMAP *buf = create_bitmap_ex(8,16,16);
13588 BITMAP *bigbmp = create_bitmap_ex(8,w,h);
13589
13590 if(buf && bigbmp)
13591 {
13592 clear_bitmap(buf);
13593
13594 if(tile)
13595 overtile16(buf, tile,0,0,cset,0);
13596
13597 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, w, h);
13598 destroy_bitmap(buf);
13599 jwin_draw_frame(screen,x,y,w+4,h+4,FR_DEEP);
13600 blit(bigbmp,screen,0,0,x+2,y+2,w,h);
13601 destroy_bitmap(bigbmp);
13602 }
13603
13604 }
13605
13606 return ret;
13607 }
13608
13609 int32_t d_nidroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13610 {
13611 int32_t ret = d_idroplist_proc(msg,d,c);
13612
13613 switch(msg)
13614 {
13615 case MSG_DRAW:
13616 case MSG_CHAR:
13617 case MSG_CLICK:
13618 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",bii[d->d1].i);
13619 }
13620
13621 return ret;
13622 }
13623
13624 // Triforce pieces
13625 static byte triframe_points[9*4] =
13626 {
13627 0,2,2,0, 2,0,4,2, 0,2,4,2, 1,1,3,1, 2,0,2,2,
13628 1,1,1,2, 1,1,2,2, 3,1,3,2, 3,1,2,2
13629 };
13630
13631 int32_t d_tri_frame_proc(int32_t msg,DIALOG *d,int32_t c)
13632 {
13633 //these are here to bypass compiler warnings about unused arguments
13634 c=c;
13635
13636 if(msg==MSG_DRAW)
13637 {
13638 int32_t x[5],y[3];
13639
13640 x[0]=d->x;
13641 x[1]=d->x+(d->w>>2);
13642 x[2]=d->x+(d->w>>1);
13643 x[3]=d->x+(d->w>>1)+(d->w>>2);
13644 x[4]=d->x+d->w;
13645 y[0]=d->y;
13646 y[1]=d->y+(d->h>>1);
13647 y[2]=d->y+d->h;
13648
13649 byte *p = triframe_points;
13650
13651 for(int32_t i=0; i<9; i++)
13652 {
13653 line(screen,x[*p],y[*(p+1)],x[*(p+2)],y[*(p+3)],d->fg);
13654 p+=4;
13655 }
13656 }
13657
13658 return D_O_K;
13659 }
13660
13661 int32_t d_tri_edit_proc(int32_t msg,DIALOG *d,int32_t c)
13662 {
13663 jwin_button_proc(msg,d,c);
13664
13665 if(msg==MSG_CLICK)
13666 {
13667 int32_t v = getnumber("Piece Number",d->d1);
13668
13669 if(v>=0)
13670 {
13671 bound(v,1,8);
13672
13673 if(v!=d->d1)
13674 {
13675 DIALOG *tp = d - d->d2;
13676
13677 for(int32_t i=0; i<8; i++)
13678 {
13679 if(tp->d1==v)
13680 {
13681 tp->d1 = d->d1;
13682 ((char*)(tp->dp))[0] = d->d1+'0';
13683 jwin_button_proc(MSG_DRAW,tp,0);
13684 }
13685
13686 ++tp;
13687 }
13688
13689 d->d1 = v;
13690 ((char*)(d->dp))[0] = v+'0';
13691 }
13692 }
13693
13694 d->flags = 0;
13695 jwin_button_proc(MSG_DRAW,d,0);
13696 }
13697
13698 return D_O_K;
13699 }
13700
13701 static DIALOG tp_dlg[] =
13702 {
13703 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13704 12 { jwin_win_proc, 56, 32, 208, 160, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
13705 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13706 12 { d_tri_frame_proc, 64, 56, 192, 96, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, NULL, NULL, NULL },
13707 // 3
13708 12 { d_tri_edit_proc, 138, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
13709 12 { d_tri_edit_proc, 166, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 1, (void *) "2", NULL, NULL },
13710 12 { d_tri_edit_proc, 90, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 2, (void *) "3", NULL, NULL },
13711 12 { d_tri_edit_proc, 214, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 3, (void *) "4", NULL, NULL },
13712 // 7
13713 12 { d_tri_edit_proc, 138, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 4, (void *) "5", NULL, NULL },
13714 12 { d_tri_edit_proc, 118, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 5, (void *) "6", NULL, NULL },
13715 12 { d_tri_edit_proc, 166, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 6, (void *) "7", NULL, NULL },
13716 12 { d_tri_edit_proc, 186, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 7, (void *) "8", NULL, NULL },
13717 // 11
13718 12 { jwin_button_proc, 90, 166, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13719 12 { jwin_button_proc, 170, 166, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13720 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13721 };
13722
13723 int32_t onTriPieces()
13724 {
13725 tp_dlg[0].dp2=get_zc_font(font_lfont);
13726 char temptext[8][2];
13727
13728 for(int32_t i=0; i<8; i++)
13729 {
13730 tp_dlg[i+3].d1 = QMisc.triforce[i];
13731 // ((char*)(tp_dlg[i+3].dp))[0] = QMisc.triforce[i]+'0';
13732 sprintf(temptext[i], "%d", QMisc.triforce[i]);
13733 tp_dlg[i+3].dp=temptext[i];
13734 }
13735
13736 large_dialog(tp_dlg);
13737
13738 if(do_zqdialog(tp_dlg,-1) == 11)
13739 {
13740 saved=false;
13741
13742 for(int32_t i=0; i<8; i++)
13743 QMisc.triforce[i] = tp_dlg[i+3].d1;
13744 }
13745
13746 return D_O_K;
13747 }
13748
13749 int32_t d_maptile_proc(int32_t msg,DIALOG *d,int32_t c);
13750 bool small_dmap=false;
13751
13752 static DIALOG dmapmaps_dlg[] =
13753 {
13754
13755 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13756 { jwin_win_proc, 4, 18, 313, 217, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Custom DMap Map Styles", NULL, NULL },
13757 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13758 { jwin_button_proc, 93, 208, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13759 { jwin_button_proc, 168, 208, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13760 { d_ctext2_proc, 160, 38, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimaps", NULL, NULL },
13761 { d_ctext2_proc, 112, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13762 { d_ctext2_proc, 208, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13763
13764 { d_ctext2_proc, 162, 110, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Large Maps", NULL, NULL },
13765 { d_ctext2_proc, 80, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13766 { d_ctext2_proc, 240, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13767 // 5
13768 { d_maptile_proc, 72, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13769 { d_maptile_proc, 168, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13770 { d_maptile_proc, 8, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13771 { d_maptile_proc, 168, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13772 // 11
13773 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13774 };
13775
13776 int32_t d_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
13777 {
13778 return jwin_hexedit_proc(msg,d,c);
13779 }
13780
13781 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13782 {
13783 if(div!=-1)
13784 rectfill(dest,x-1,y-1,x+63,y+3,div);
13785
13786 for(int32_t dx=0; dx<64; dx+=8)
13787 {
13788 if(grid&0x80)
13789 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13790 else if(bg!=-1)
13791 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13792
13793 grid<<=1;
13794 }
13795 }
13796
13797 void drawovergrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t color,int32_t div)
13798 {
13799 if(div!=-1)
13800 rectfill(dest,x-1,y-1,x+63,y+3,div);
13801
13802 for(int32_t dx=0; dx<64; dx+=4)
13803 {
13804 rectfill(dest,x+dx,y,x+dx+2,y+2,color);
13805 grid<<=1;
13806 }
13807 }
13808
13809 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t w, int32_t h, int32_t tw, int32_t th, int32_t *grid,int32_t fg,int32_t bg,int32_t div)
13810 {
13811 //these are here to bypass compiler warnings about unused arguments
13812 w=w;
13813 tw=tw;
13814 th=th;
13815
13816 rectfill(dest,x,y,x+(8*8),y+(1*4),div);
13817
13818 for(int32_t dy=0; dy<h; dy++)
13819 {
13820 for(int32_t dx=0; dx<64; dx+=8)
13821 {
13822 if(grid[0]&0x80)
13823 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13824 else
13825 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13826
13827 grid[0]<<=1;
13828 }
13829 }
13830 }
13831
13832 void drawgrid_s(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13833 {
13834 rectfill(dest,x-1,y-1,x+63,y+3,div);
13835
13836 for(int32_t dx=0; dx<64; dx+=8)
13837 {
13838 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13839
13840 if(grid&0x80)
13841 rectfill(dest,x+dx+2,y,x+dx+4,y+2,fg);
13842
13843 grid<<=1;
13844 }
13845 }
13846
13847 void drawdmap(int32_t dmap)
13848 {
13849 int32_t c;
13850 zcolors mc=QMisc.colors;
13851
13852 switch((DMaps[dmap].type&dmfTYPE))
13853 {
13854 case dmDNGN:
13855 case dmCAVE:
13856 clear_bitmap(dmapbmp_small);
13857
13858 if(DMaps[dmap].minimap_2_tile)
13859 ;
13860 // overworld_map_tile overrides the NES minimap. dungeon_map_tile does not.
13861 else for(int32_t y=1; y<33; y+=4)
13862 drawgrid(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2], DMaps[dmap].flags&dmfMINIMAPCOLORFIX ? mc.cave_fg : mc.dngn_fg, -1, -1);
13863
13864 c=DMaps[dmap].compass;
13865 // rectfill(dmapbmp,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,dvc(2*4));
13866 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(4));
13867 c=DMaps[dmap].cont;
13868 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13869 break;
13870
13871 case dmOVERW:
13872 clear_bitmap(dmapbmp_small);
13873
13874 if(DMaps[dmap].minimap_2_tile)
13875 ;
13876 else if(!mc.overworld_map_tile)
13877 for(int32_t y=1; y<33; y+=4)
13878 drawovergrid(dmapbmp_small,1,y,DMaps[dmap].grid[y>>2],mc.overw_bg,vc(0));
13879
13880 c=DMaps[dmap].cont;
13881 rectfill(dmapbmp_small,(c&15)*4+1,(c>>4)*4+1,(c&15)*4+3,(c>>4)*4+3,vc(10));
13882 break;
13883
13884 case dmBSOVERW:
13885 clear_bitmap(dmapbmp_small);
13886
13887 if(DMaps[dmap].minimap_2_tile)
13888 ;
13889 else if(!mc.overworld_map_tile)
13890 for(int32_t y=1; y<33; y+=4)
13891 // drawgrid_s(dmapbmp,1,y,DMaps[dmap].grid[y>>2],dvc(2*4),dvc(2*3),dvc(3+4));
13892 drawgrid_s(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2],mc.bs_goal,mc.bs_dk,vc(14));
13893
13894 c=DMaps[dmap].cont;
13895 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13896 break;
13897 }
13898 }
13899
13900 void drawdmap_screen(int32_t x, int32_t y, int32_t w, int32_t h, int32_t dmap)
13901 {
13902 BITMAP *tempbmp = create_bitmap_ex(8,w,h);
13903 clear_to_color(tempbmp, vc(0));
13904 zcolors mc=QMisc.colors;
13905
13906 // rectfill(tempbmp,x,y,x+w-1,y+h-1,vc(0));
13907
13908 if(DMaps[dmap].minimap_2_tile)
13909 {
13910 draw_block(tempbmp,0,0,DMaps[dmap].minimap_2_tile,DMaps[dmap].minimap_2_cset,5,3);
13911 }
13912 else if(((DMaps[dmap].type&dmfTYPE)==dmDNGN || (DMaps[dmap].type&dmfTYPE)==dmCAVE) && mc.dungeon_map_tile)
13913 {
13914 draw_block(tempbmp,0,0,mc.dungeon_map_tile,mc.dungeon_map_cset,5,3);
13915 }
13916 else if(((DMaps[dmap].type&dmfTYPE)==dmOVERW || (DMaps[dmap].type&dmfTYPE)==dmBSOVERW) && mc.overworld_map_tile)
13917 {
13918 draw_block(tempbmp,0,0,mc.overworld_map_tile,mc.overworld_map_cset,5,3);
13919 }
13920
13921 masked_blit(dmapbmp_small,tempbmp,0,0,8,7,65,33);
13922
13923 blit(tempbmp,screen,0,0,x,y,w,h);
13924 destroy_bitmap(tempbmp);
13925
13926 }
13927
13928 int32_t d_dmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13929 {
13930 if(msg==MSG_DRAW)
13931 {
13932 int32_t dmap = d->d1;
13933 int32_t xy[6] = {44,92,128,100,128,110};
13934 //int32_t *xy = (int32_t*)(d->dp3);
13935 float temp_scale = 1.5;
13936
13937 drawdmap(dmap);
13938
13939 if(xy[0]>-1000&&xy[1]>-1000)
13940 {
13941 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13942 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13943 int32_t w = 84;
13944 int32_t h = 52;
13945 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13946 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13947 }
13948
13949 if(xy[2]>-1000&&xy[3]>-1000)
13950 {
13951 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13952 }
13953
13954 if(xy[4]>-1000&&xy[5]>-1000)
13955 {
13956 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13957 }
13958 }
13959
13960 return jwin_list_proc(msg,d,c);
13961 }
13962
13963 int32_t d_dropdmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13964 {
13965 if(msg==MSG_DRAW)
13966 {
13967 int32_t dmap = d->d1;
13968 int32_t *xy = (int32_t*)(d->dp3);
13969 float temp_scale = 1.5;
13970
13971 drawdmap(dmap);
13972
13973 if(xy[0]>-1000&&xy[1]>-1000)
13974 {
13975 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13976 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13977 int32_t w = 84;
13978 int32_t h = 52;
13979 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13980 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13981 }
13982
13983 if(xy[2]>-1000&&xy[3]>-1000)
13984 {
13985 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13986 }
13987
13988 if(xy[4]>-1000&&xy[5]>-1000)
13989 {
13990 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13991 }
13992 }
13993
13994 return jwin_droplist_proc(msg,d,c);
13995 }
13996
13997 void drawxmap(ALLEGRO_BITMAP* dest, int32_t themap, int32_t xoff, bool large, int dx, int dy)
13998 {
13999 ALLEGRO_STATE old_state;
14000 al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
14001
14002 al_set_target_bitmap(dest);
14003 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
14004
14005 int32_t cols = (large ? 8 : 16);
14006 int32_t col_width = large ? 22 : 11;
14007 int32_t dot_width = (large ? 6 : 4);
14008 int32_t dot_offset = (large ? 7 : 3);
14009 int32_t l = 10;
14010
14011 for (int32_t y = 0; y < 8; y++)
14012 {
14013 // Users might have set the dmap to a map that has since been deleted.
14014 if (themap >= Map.getMapCount())
14015 break;
14016
14017 for (int32_t x = 0; x < cols; x++)
14018 {
14019 if (x + xoff < 0 || x + xoff > 15)
14020 continue;
14021
14022 const mapscr* scr = get_canonical_scr(themap, y * 16 + x + (large ? xoff : 0));
14023 if (!(scr->valid & mVALID))
14024 continue;
14025
14026 al_draw_filled_rectangle(dx + (x * col_width), dy + (y * l), dx + (x * col_width + col_width), dy + ((y * l) + l), real_lc1(scr->color));
14027 al_draw_filled_rectangle(dx + (x * col_width + dot_offset), dy + (y * l + 3), dx + (x * col_width + dot_offset + dot_width), dy + (y * l + l - 3), real_lc2(scr->color));
14028 }
14029 }
14030
14031 al_restore_state(&old_state);
14032 }
14033
14034 const char *dmapscriptdroplist(int32_t index, int32_t *list_size)
14035 {
14036 if(index<0)
14037 {
14038 *list_size = bidmaps_cnt;
14039 return NULL;
14040 }
14041
14042 return bidmaps[index].first.c_str();
14043 }
14044
14045 12 static ListData dmapscript_list(dmapscriptdroplist, &a4fonts[font_pfont]);
14046
14047 //int32_t selectdmapxy[6] = {90,142,164,150,164,160};
14048 int32_t selectdmapxy[6] = {44,92,128,100,128,110};
14049
14050 12 static ListData dmap_list(dmaplist, &font);
14051
14052 static DIALOG selectdmap_dlg[] =
14053 {
14054 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14055 12 { jwin_win_proc, 72-44, 56-30, 176+88+1, 120+74+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select DMap", NULL, NULL },
14056 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14057 12 { d_dmaplist_proc, 46, 50, 64+72+88+1, 60+24+1+2, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &dmap_list, NULL, selectdmapxy },
14058 12 { jwin_button_proc, 90, 152+44, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
14059 12 { jwin_button_proc, 170, 152+44, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
14060 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
14061 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_C, (void*)close_dlg, NULL, NULL },
14062 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_V, (void*)close_dlg, NULL, NULL },
14063 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14064 };
14065
14066 12 static dmap copiedDMap;
14067 static byte dmapcopied = 0;
14068
14069 int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
14070 {
14071
14072 dword section_version=V_DMAPS;
14073 int32_t zversion = ZELDA_VERSION;
14074 int32_t zbuild = VERSION_BUILD;
14075
14076 if(!p_iputl(V_ZDMAP,f))
14077 {
14078 return 0;
14079 }
14080
14081 //section version info
14082 if(!p_iputl(zversion,f))
14083 {
14084 return 0;
14085 }
14086 if(!p_iputl(zbuild,f))
14087 {
14088 return 0;
14089 }
14090 if(!p_iputw(section_version,f))
14091 {
14092 new_return(2);
14093 }
14094
14095 if(!write_deprecated_section_cversion(section_version, f))
14096 {
14097 new_return(3);
14098 }
14099 //max possible at this time
14100 if(!p_iputl(max,f))
14101 {
14102 new_return(4);
14103 }
14104 //first id written
14105 if(!p_iputl(first,f))
14106 {
14107 new_return(5);
14108 }
14109 //last id written
14110 if(!p_iputl(last,f))
14111 {
14112 new_return(6);
14113 }
14114 int32_t count = last-first;
14115 //number written
14116 if(!p_iputl(count,f))
14117 {
14118 new_return(7);
14119 }
14120
14121
14122 for ( int32_t i = first; i <= last; ++i )
14123 {
14124 if ( i > max ) break;
14125
14126 if(!p_putc(DMaps[i].map,f))
14127 {
14128 new_return(8);
14129 }
14130
14131 if(!p_iputw(DMaps[i].level,f))
14132 {
14133 new_return(9);
14134 }
14135
14136 if(!p_putc(DMaps[i].xoff,f))
14137 {
14138 new_return(10);
14139 }
14140
14141 if(!p_putc(DMaps[i].compass,f))
14142 {
14143 new_return(11);
14144 }
14145
14146 if(!p_iputw(DMaps[i].color,f))
14147 {
14148 new_return(12);
14149 }
14150
14151 if(!p_putc(DMaps[i].midi,f))
14152 {
14153 new_return(13);
14154 }
14155
14156 if(!p_putc(DMaps[i].cont,f))
14157 {
14158 new_return(14);
14159 }
14160
14161 if(!p_putc(DMaps[i].type,f))
14162 {
14163 new_return(15);
14164 }
14165
14166 for(int32_t j=0; j<8; j++)
14167 {
14168 if(!p_putc(DMaps[i].grid[j],f))
14169 {
14170 new_return(16);
14171 }
14172 }
14173
14174 //16
14175 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14176 {
14177 new_return(17);
14178 }
14179
14180 if(!p_putwstr(DMaps[i].title,f))
14181 {
14182 new_return(18);
14183 }
14184
14185 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14186 {
14187 new_return(19);
14188 }
14189
14190 if(!p_iputl(DMaps[i].minimap_1_tile,f))
14191 {
14192 new_return(20);
14193 }
14194
14195 if(!p_putc(DMaps[i].minimap_1_cset,f))
14196 {
14197 new_return(21);
14198 }
14199
14200 if(!p_iputl(DMaps[i].minimap_2_tile,f))
14201 {
14202 new_return(22);
14203 }
14204
14205 if(!p_putc(DMaps[i].minimap_2_cset,f))
14206 {
14207 new_return(23);
14208 }
14209
14210 if(!p_iputl(DMaps[i].largemap_1_tile,f))
14211 {
14212 new_return(24);
14213 }
14214
14215 if(!p_putc(DMaps[i].largemap_1_cset,f))
14216 {
14217 new_return(25);
14218 }
14219
14220 if(!p_iputl(DMaps[i].largemap_2_tile,f))
14221 {
14222 new_return(26);
14223 }
14224
14225 if(!p_putc(DMaps[i].largemap_2_cset,f))
14226 {
14227 new_return(27);
14228 }
14229
14230 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14231 {
14232 new_return(28);
14233 }
14234
14235 if(!p_putc(DMaps[i].tmusictrack,f))
14236 {
14237 new_return(29);
14238 }
14239
14240 if(!p_putc(DMaps[i].active_subscreen,f))
14241 {
14242 new_return(30);
14243 }
14244
14245 if(!p_putc(DMaps[i].passive_subscreen,f))
14246 {
14247 new_return(31);
14248 }
14249
14250 byte disabled[32];
14251 memset(disabled,0,32);
14252
14253 for(int32_t j=0; j<MAXITEMS; j++)
14254 {
14255 if(DMaps[i].disableditems[j])
14256 {
14257 disabled[j/8] |= (1 << (j%8));
14258 }
14259 }
14260
14261 if(!pfwrite(disabled,32,f))
14262 {
14263 new_return(32);
14264 }
14265
14266 if(!p_iputl(DMaps[i].flags,f))
14267 {
14268 new_return(33);
14269 }
14270 if(!p_putc(DMaps[i].sideview,f))
14271 {
14272 new_return(30);
14273 }
14274 if(!p_iputw(DMaps[i].script,f))
14275 {
14276 new_return(31);
14277 }
14278 for ( int32_t q = 0; q < 8; q++ )
14279 {
14280 if(!p_iputl(DMaps[i].initD[q],f))
14281 {
14282 new_return(32);
14283 }
14284
14285 }
14286 for ( int32_t q = 0; q < 8; q++ )
14287 {
14288 for ( int32_t w = 0; w < 65; w++ )
14289 {
14290 if (!p_putc(DMaps[i].initD_label[q][w],f))
14291 {
14292 new_return(33);
14293 }
14294 }
14295 }
14296 if(!p_iputw(DMaps[i].active_sub_script,f))
14297 {
14298 new_return(34);
14299 }
14300 if(!p_iputw(DMaps[i].passive_sub_script,f))
14301 {
14302 new_return(35);
14303 }
14304 for(int32_t q = 0; q < 8; ++q)
14305 {
14306 if(!p_iputl(DMaps[i].sub_initD[q],f))
14307 {
14308 new_return(36);
14309 }
14310 }
14311 for(int32_t q = 0; q < 8; ++q)
14312 {
14313 for(int32_t w = 0; w < 65; ++w)
14314 {
14315 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14316 {
14317 new_return(37);
14318 }
14319 }
14320 }
14321 if(!p_iputw(DMaps[i].onmap_script,f))
14322 {
14323 new_return(35);
14324 }
14325 for(int32_t q = 0; q < 8; ++q)
14326 {
14327 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14328 {
14329 new_return(36);
14330 }
14331 }
14332 for(int32_t q = 0; q < 8; ++q)
14333 {
14334 for(int32_t w = 0; w < 65; ++w)
14335 {
14336 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14337 {
14338 new_return(37);
14339 }
14340 }
14341 }
14342 if (!p_iputw(DMaps[i].mirrorDMap, f))
14343 {
14344 new_return(38);
14345 }
14346 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14347 {
14348 new_return(39);
14349 }
14350 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14351 {
14352 new_return(40);
14353 }
14354 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14355 {
14356 new_return(41);
14357 }
14358 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14359 {
14360 new_return(42);
14361 }
14362 }
14363
14364 return 1;
14365 }
14366
14367
14368 int32_t readsomedmaps(PACKFILE *f)
14369 {
14370 dword section_version = 0;
14371 int32_t zversion = 0;
14372 int32_t zbuild = 0;
14373 dmap tempdmap{};
14374
14375 int32_t first = 0, last = 0, max = 0, count = 0;
14376 int32_t datatype_version = 0;
14377
14378 //char dmapstring[64]={0};
14379 //section version info
14380 if(!p_igetl(&datatype_version,f))
14381 {
14382 return 0;
14383 }
14384 if ( datatype_version < 0 )
14385 {
14386 if(!p_igetl(&zversion,f))
14387 {
14388 return 0;
14389 }
14390 }
14391 else
14392 {
14393 zversion = datatype_version;
14394 }
14395 if(!p_igetl(&zbuild,f))
14396 {
14397 return 0;
14398 }
14399
14400 if(!p_igetw(&section_version,f))
14401 {
14402 return 0;
14403 }
14404
14405 if(!read_deprecated_section_cversion(f))
14406 {
14407 return 0;
14408 }
14409 if ( datatype_version < 0 )
14410 {
14411 if(!p_igetl(&max,f))
14412 {
14413 return 0;
14414 }
14415 if(!p_igetl(&first,f))
14416 {
14417 return 0;
14418 }
14419 if(!p_igetl(&last,f))
14420 {
14421 return 0;
14422 }
14423 if(!p_igetl(&count,f))
14424 {
14425 return 0;
14426 }
14427 }
14428 else
14429 {
14430 first = 0;
14431 last = 0;
14432 count = 1;
14433 max = 255;
14434 }
14435
14436
14437
14438
14439 al_trace("readsomedmaps section_version: %d\n", section_version);
14440
14441 if ( zversion > ZELDA_VERSION )
14442 {
14443 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
14444 return 0;
14445 }
14446 else if (( section_version > V_DMAPS ))
14447 {
14448 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
14449 return 0;
14450 }
14451 else
14452 {
14453 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
14454 }
14455 //if(!pfread(&dmapstring, 64, f))
14456 //{
14457 // return 0;
14458 //}
14459
14460
14461
14462 for ( int32_t i = first; i <= last; ++i )
14463 {
14464 if(!p_getc(&tempdmap.map,f))
14465 {
14466 return 0;
14467 }
14468
14469 if(!p_igetw(&tempdmap.level,f))
14470 {
14471 return 0;
14472 }
14473
14474 if(!p_getc(&tempdmap.xoff,f))
14475 {
14476 return 0;
14477 }
14478
14479 if(!p_getc(&tempdmap.compass,f))
14480 {
14481 return 0;
14482 }
14483
14484 if(!p_igetw(&tempdmap.color,f))
14485 {
14486 return 0;
14487 }
14488
14489 if(!p_getc(&tempdmap.midi,f))
14490 {
14491 return 0;
14492 }
14493
14494 if(!p_getc(&tempdmap.cont,f))
14495 {
14496 return 0;
14497 }
14498
14499 if(!p_getc(&tempdmap.type,f))
14500 {
14501 return 0;
14502 }
14503
14504 for(int32_t j=0; j<8; j++)
14505 {
14506 if(!p_getc(&tempdmap.grid[j],f))
14507 {
14508 return 0;
14509 }
14510 }
14511
14512 //16
14513 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
14514 {
14515 return 0;
14516 }
14517
14518 if (section_version<20)
14519 {
14520 char title[22];
14521 if (!p_getstr(title, sizeof(title) - 1, f))
14522 {
14523 return 0;
14524 }
14525 tempdmap.title.assign(title);
14526 }
14527 else
14528 {
14529 if (!p_getwstr(&tempdmap.title, f))
14530 {
14531 return 0;
14532 }
14533 }
14534
14535 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
14536 {
14537 return 0;
14538 }
14539
14540 if(!p_igetl(&tempdmap.minimap_1_tile,f))
14541 {
14542 return 0;
14543 }
14544
14545 if(!p_getc(&tempdmap.minimap_1_cset,f))
14546 {
14547 return 0;
14548 }
14549
14550 if(!p_igetl(&tempdmap.minimap_2_tile,f))
14551 {
14552 return 0;
14553 }
14554
14555 if(!p_getc(&tempdmap.minimap_2_cset,f))
14556 {
14557 return 0;
14558 }
14559
14560 if(!p_igetl(&tempdmap.largemap_1_tile,f))
14561 {
14562 return 0;
14563 }
14564
14565 if(!p_getc(&tempdmap.largemap_1_cset,f))
14566 {
14567 return 0;
14568 }
14569
14570 if(!p_igetl(&tempdmap.largemap_2_tile,f))
14571 {
14572 return 0;
14573 }
14574
14575 if(!p_getc(&tempdmap.largemap_2_cset,f))
14576 {
14577 return 0;
14578 }
14579
14580 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
14581 {
14582 return 0;
14583 }
14584
14585 if(!p_getc(&tempdmap.tmusictrack,f))
14586 {
14587 return 0;
14588 }
14589
14590 if(!p_getc(&tempdmap.active_subscreen,f))
14591 {
14592 return 0;
14593 }
14594
14595 if(!p_getc(&tempdmap.passive_subscreen,f))
14596 {
14597 return 0;
14598 }
14599
14600 byte disabled[32];
14601 memset(disabled,0,32);
14602
14603 if(!pfread(&disabled, 32, f)) return 0;
14604
14605 for(int32_t j=0; j<MAXITEMS; j++)
14606 {
14607 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
14608 else tempdmap.disableditems[j]=0;
14609 }
14610
14611
14612 if(!p_igetl(&tempdmap.flags,f))
14613 {
14614 return 0;
14615 }
14616 if ( zversion >= 0x255 )
14617 {
14618 if ( section_version >= 14 )
14619 {
14620 //2.55 starts here
14621 if(!p_getc(&tempdmap.sideview,f))
14622 {
14623 return 0;
14624 }
14625 if(!p_igetw(&tempdmap.script,f))
14626 {
14627 return 0;
14628 }
14629 for ( int32_t q = 0; q < 8; q++ )
14630 {
14631 if(!p_igetl(&tempdmap.initD[q],f))
14632 {
14633 return 0;
14634 }
14635
14636 }
14637 for ( int32_t q = 0; q < 8; q++ )
14638 {
14639 for ( int32_t w = 0; w < 65; w++ )
14640 {
14641 if (!p_getc(&tempdmap.initD_label[q][w],f))
14642 {
14643 return 0;
14644 }
14645 }
14646 }
14647 if(!p_igetw(&tempdmap.active_sub_script,f))
14648 {
14649 return 0;
14650 }
14651 if(!p_igetw(&tempdmap.passive_sub_script,f))
14652 {
14653 return 0;
14654 }
14655 for(int32_t q = 0; q < 8; ++q)
14656 {
14657 if(!p_igetl(&tempdmap.sub_initD[q],f))
14658 {
14659 return 0;
14660 }
14661 }
14662 for(int32_t q = 0; q < 8; ++q)
14663 {
14664 for(int32_t w = 0; w < 65; ++w)
14665 {
14666 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
14667 {
14668 return 0;
14669 }
14670 }
14671 }
14672 if(!p_igetw(&tempdmap.onmap_script,f))
14673 {
14674 return 0;
14675 }
14676 for(int32_t q = 0; q < 8; ++q)
14677 {
14678 if(!p_igetl(&tempdmap.onmap_initD[q],f))
14679 {
14680 return 0;
14681 }
14682 }
14683 for(int32_t q = 0; q < 8; ++q)
14684 {
14685 for(int32_t w = 0; w < 65; ++w)
14686 {
14687 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
14688 {
14689 return 0;
14690 }
14691 }
14692 }
14693 if (!p_igetw(&tempdmap.mirrorDMap, f))
14694 {
14695 return 0;
14696 }
14697 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
14698 {
14699 return 0;
14700 }
14701 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
14702 {
14703 return 0;
14704 }
14705 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
14706 {
14707 return 0;
14708 }
14709 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
14710 {
14711 return 0;
14712 }
14713 }
14714 }
14715 DMaps[i].clear();
14716 DMaps[i] = tempdmap;
14717 }
14718
14719 return 1;
14720 }
14721
14722
14723
14724 int32_t writeonedmap(PACKFILE *f, int32_t i)
14725 {
14726
14727 dword section_version=V_DMAPS;
14728 int32_t zversion = ZELDA_VERSION;
14729 int32_t zbuild = VERSION_BUILD;
14730
14731
14732 //section version info
14733 if(!p_iputl(V_ZDMAP,f))
14734 {
14735 return 0;
14736 }
14737 if(!p_iputl(zversion,f))
14738 {
14739 return 0;
14740 }
14741 if(!p_iputl(zbuild,f))
14742 {
14743 return 0;
14744 }
14745 if(!p_iputw(section_version,f))
14746 {
14747 new_return(2);
14748 }
14749
14750 if(!write_deprecated_section_cversion(section_version, f))
14751 {
14752 new_return(3);
14753 }
14754
14755
14756
14757 if(!p_putc(DMaps[i].map,f))
14758 {
14759 new_return(6);
14760 }
14761
14762 if(!p_iputw(DMaps[i].level,f))
14763 {
14764 new_return(7);
14765 }
14766
14767 if(!p_putc(DMaps[i].xoff,f))
14768 {
14769 new_return(8);
14770 }
14771
14772 if(!p_putc(DMaps[i].compass,f))
14773 {
14774 new_return(9);
14775 }
14776
14777 if(!p_iputw(DMaps[i].color,f))
14778 {
14779 new_return(10);
14780 }
14781
14782 if(!p_putc(DMaps[i].midi,f))
14783 {
14784 new_return(11);
14785 }
14786
14787 if(!p_putc(DMaps[i].cont,f))
14788 {
14789 new_return(12);
14790 }
14791
14792 if(!p_putc(DMaps[i].type,f))
14793 {
14794 new_return(13);
14795 }
14796
14797 for(int32_t j=0; j<8; j++)
14798 {
14799 if(!p_putc(DMaps[i].grid[j],f))
14800 {
14801 new_return(14);
14802 }
14803 }
14804
14805 //16
14806 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14807 {
14808 new_return(15);
14809 }
14810
14811 if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
14812 {
14813 new_return(16);
14814 }
14815
14816 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14817 {
14818 new_return(17);
14819 }
14820
14821 if(!p_iputl(DMaps[i].minimap_1_tile,f))
14822 {
14823 new_return(18);
14824 }
14825
14826 if(!p_putc(DMaps[i].minimap_1_cset,f))
14827 {
14828 new_return(19);
14829 }
14830
14831 if(!p_iputl(DMaps[i].minimap_2_tile,f))
14832 {
14833 new_return(20);
14834 }
14835
14836 if(!p_putc(DMaps[i].minimap_2_cset,f))
14837 {
14838 new_return(21);
14839 }
14840
14841 if(!p_iputl(DMaps[i].largemap_1_tile,f))
14842 {
14843 new_return(22);
14844 }
14845
14846 if(!p_putc(DMaps[i].largemap_1_cset,f))
14847 {
14848 new_return(23);
14849 }
14850
14851 if(!p_iputl(DMaps[i].largemap_2_tile,f))
14852 {
14853 new_return(24);
14854 }
14855
14856 if(!p_putc(DMaps[i].largemap_2_cset,f))
14857 {
14858 new_return(25);
14859 }
14860
14861 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14862 {
14863 new_return(26);
14864 }
14865
14866 if(!p_putc(DMaps[i].tmusictrack,f))
14867 {
14868 new_return(25);
14869 }
14870
14871 if(!p_putc(DMaps[i].active_subscreen,f))
14872 {
14873 new_return(26);
14874 }
14875
14876 if(!p_putc(DMaps[i].passive_subscreen,f))
14877 {
14878 new_return(27);
14879 }
14880
14881 byte disabled[32];
14882 memset(disabled,0,32);
14883
14884 for(int32_t j=0; j<MAXITEMS; j++)
14885 {
14886 if(DMaps[i].disableditems[j])
14887 {
14888 disabled[j/8] |= (1 << (j%8));
14889 }
14890 }
14891
14892 if(!pfwrite(disabled,32,f))
14893 {
14894 new_return(28);
14895 }
14896
14897 if(!p_iputl(DMaps[i].flags,f))
14898 {
14899 new_return(29);
14900 }
14901 if(!p_putc(DMaps[i].sideview,f))
14902 {
14903 new_return(30);
14904 }
14905 if(!p_iputw(DMaps[i].script,f))
14906 {
14907 new_return(31);
14908 }
14909 for ( int32_t q = 0; q < 8; q++ )
14910 {
14911 if(!p_iputl(DMaps[i].initD[q],f))
14912 {
14913 new_return(32);
14914 }
14915
14916 }
14917 for ( int32_t q = 0; q < 8; q++ )
14918 {
14919 for ( int32_t w = 0; w < 65; w++ )
14920 {
14921 if (!p_putc(DMaps[i].initD_label[q][w],f))
14922 {
14923 new_return(33);
14924 }
14925 }
14926 }
14927 if(!p_iputw(DMaps[i].active_sub_script,f))
14928 {
14929 new_return(34);
14930 }
14931 if(!p_iputw(DMaps[i].passive_sub_script,f))
14932 {
14933 new_return(35);
14934 }
14935 for(int32_t q = 0; q < 8; ++q)
14936 {
14937 if(!p_iputl(DMaps[i].sub_initD[q],f))
14938 {
14939 new_return(36);
14940 }
14941 }
14942 for(int32_t q = 0; q < 8; ++q)
14943 {
14944 for(int32_t w = 0; w < 65; ++w)
14945 {
14946 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14947 {
14948 new_return(37);
14949 }
14950 }
14951 }
14952 if(!p_iputw(DMaps[i].onmap_script,f))
14953 {
14954 new_return(35);
14955 }
14956 for(int32_t q = 0; q < 8; ++q)
14957 {
14958 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14959 {
14960 new_return(36);
14961 }
14962 }
14963 for(int32_t q = 0; q < 8; ++q)
14964 {
14965 for(int32_t w = 0; w < 65; ++w)
14966 {
14967 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14968 {
14969 new_return(37);
14970 }
14971 }
14972 }
14973 if (!p_iputw(DMaps[i].mirrorDMap, f))
14974 {
14975 new_return(38);
14976 }
14977 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14978 {
14979 new_return(39);
14980 }
14981 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14982 {
14983 new_return(40);
14984 }
14985 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14986 {
14987 new_return(41);
14988 }
14989 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14990 {
14991 new_return(42);
14992 }
14993
14994 return 1;
14995 }
14996
14997
14998 int32_t readonedmap(PACKFILE *f, int32_t index)
14999 {
15000 dword section_version = 0;
15001 int32_t zversion = 0;
15002 int32_t zbuild = 0;
15003 dmap tempdmap{};
15004 int32_t datatype_version = 0;
15005 int32_t first = 0;
15006 int32_t last = 0;
15007 int32_t max = 0;
15008 int32_t count = 0;
15009
15010 //char dmapstring[64]={0};
15011 //section version info
15012 if(!p_igetl(&datatype_version,f))
15013 {
15014 return 0;
15015 }
15016 if ( datatype_version < 0 )
15017 {
15018 if(!p_igetl(&zversion,f))
15019 {
15020 return 0;
15021 }
15022 }
15023 else
15024 {
15025 zversion = datatype_version;
15026 }
15027 if(!p_igetl(&zbuild,f))
15028 {
15029 return 0;
15030 }
15031
15032 if(!p_igetw(&section_version,f))
15033 {
15034 return 0;
15035 }
15036
15037 if(!read_deprecated_section_cversion(f))
15038 {
15039 return 0;
15040 }
15041 al_trace("readonedmap section_version: %d\n", section_version);
15042
15043
15044 if ( datatype_version < 0 )
15045 {
15046 if(!p_igetl(&max,f))
15047 {
15048 return 0;
15049 }
15050 if(!p_igetl(&first,f))
15051 {
15052 return 0;
15053 }
15054 if(!p_igetl(&last,f))
15055 {
15056 return 0;
15057 }
15058 if(!p_igetl(&count,f))
15059 {
15060 return 0;
15061 }
15062 }
15063 if ( zversion > ZELDA_VERSION )
15064 {
15065 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
15066 return 0;
15067 }
15068 else if (( section_version > V_DMAPS ))
15069 {
15070 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d)\n", section_version);
15071 return 0;
15072 }
15073 else
15074 {
15075 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
15076 }
15077 //if(!pfread(&dmapstring, 64, f))
15078 //{
15079 // return 0;
15080 //}
15081
15082
15083
15084
15085 if(!p_getc(&tempdmap.map,f))
15086 {
15087 return 0;
15088 }
15089
15090 if(!p_igetw(&tempdmap.level,f))
15091 {
15092 return 0;
15093 }
15094
15095 if(!p_getc(&tempdmap.xoff,f))
15096 {
15097 return 0;
15098 }
15099
15100 if(!p_getc(&tempdmap.compass,f))
15101 {
15102 return 0;
15103 }
15104
15105 if(!p_igetw(&tempdmap.color,f))
15106 {
15107 return 0;
15108 }
15109
15110 if(!p_getc(&tempdmap.midi,f))
15111 {
15112 return 0;
15113 }
15114
15115 if(!p_getc(&tempdmap.cont,f))
15116 {
15117 return 0;
15118 }
15119
15120 if(!p_getc(&tempdmap.type,f))
15121 {
15122 return 0;
15123 }
15124
15125 for(int32_t j=0; j<8; j++)
15126 {
15127 if(!p_getc(&tempdmap.grid[j],f))
15128 {
15129 return 0;
15130 }
15131 }
15132
15133 //16
15134 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
15135 {
15136 return 0;
15137 }
15138
15139 if (section_version<20)
15140 {
15141 char title[22];
15142 if (!p_getstr(title, sizeof(title) - 1, f))
15143 {
15144 return 0;
15145 }
15146 tempdmap.title.assign(title);
15147 }
15148 else
15149 {
15150 if (!p_getwstr(&tempdmap.title, f))
15151 {
15152 return 0;
15153 }
15154 }
15155
15156 if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
15157 {
15158 return 0;
15159 }
15160
15161 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
15162 {
15163 return 0;
15164 }
15165
15166 if(!p_igetl(&tempdmap.minimap_1_tile,f))
15167 {
15168 return 0;
15169 }
15170
15171 if(!p_getc(&tempdmap.minimap_1_cset,f))
15172 {
15173 return 0;
15174 }
15175
15176 if(!p_igetl(&tempdmap.minimap_2_tile,f))
15177 {
15178 return 0;
15179 }
15180
15181 if(!p_getc(&tempdmap.minimap_2_cset,f))
15182 {
15183 return 0;
15184 }
15185
15186 if(!p_igetl(&tempdmap.largemap_1_tile,f))
15187 {
15188 return 0;
15189 }
15190
15191 if(!p_getc(&tempdmap.largemap_1_cset,f))
15192 {
15193 return 0;
15194 }
15195
15196 if(!p_igetl(&tempdmap.largemap_2_tile,f))
15197 {
15198 return 0;
15199 }
15200
15201 if(!p_getc(&tempdmap.largemap_2_cset,f))
15202 {
15203 return 0;
15204 }
15205
15206 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
15207 {
15208 return 0;
15209 }
15210
15211 if(!p_getc(&tempdmap.tmusictrack,f))
15212 {
15213 return 0;
15214 }
15215
15216 if(!p_getc(&tempdmap.active_subscreen,f))
15217 {
15218 return 0;
15219 }
15220
15221 if(!p_getc(&tempdmap.passive_subscreen,f))
15222 {
15223 return 0;
15224 }
15225
15226 byte disabled[32];
15227 memset(disabled,0,32);
15228
15229 if(!pfread(&disabled, 32, f)) return 0;
15230
15231 for(int32_t j=0; j<MAXITEMS; j++)
15232 {
15233 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
15234 else tempdmap.disableditems[j]=0;
15235 }
15236
15237
15238 if(!p_igetl(&tempdmap.flags,f))
15239 {
15240 return 0;
15241 }
15242 if ( zversion >= 0x255 )
15243 {
15244 if ( section_version >= 14 )
15245 {
15246 //2.55 starts here
15247 if(!p_getc(&tempdmap.sideview,f))
15248 {
15249 return 0;
15250 }
15251 if(!p_igetw(&tempdmap.script,f))
15252 {
15253 return 0;
15254 }
15255 for ( int32_t q = 0; q < 8; q++ )
15256 {
15257 if(!p_igetl(&tempdmap.initD[q],f))
15258 {
15259 return 0;
15260 }
15261
15262 }
15263 for ( int32_t q = 0; q < 8; q++ )
15264 {
15265 for ( int32_t w = 0; w < 65; w++ )
15266 {
15267 if (!p_getc(&tempdmap.initD_label[q][w],f))
15268 {
15269 return 0;
15270 }
15271 }
15272 }
15273 if(!p_igetw(&tempdmap.active_sub_script,f))
15274 {
15275 return 0;
15276 }
15277 if(!p_igetw(&tempdmap.passive_sub_script,f))
15278 {
15279 return 0;
15280 }
15281 for(int32_t q = 0; q < 8; ++q)
15282 {
15283 if(!p_igetl(&tempdmap.sub_initD[q],f))
15284 {
15285 return 0;
15286 }
15287 }
15288 for(int32_t q = 0; q < 8; ++q)
15289 {
15290 for(int32_t w = 0; w < 65; ++w)
15291 {
15292 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
15293 {
15294 return 0;
15295 }
15296 }
15297 }
15298 if(!p_igetw(&tempdmap.onmap_script,f))
15299 {
15300 return 0;
15301 }
15302 for(int32_t q = 0; q < 8; ++q)
15303 {
15304 if(!p_igetl(&tempdmap.onmap_initD[q],f))
15305 {
15306 return 0;
15307 }
15308 }
15309 for(int32_t q = 0; q < 8; ++q)
15310 {
15311 for(int32_t w = 0; w < 65; ++w)
15312 {
15313 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
15314 {
15315 return 0;
15316 }
15317 }
15318 }
15319 if (!p_igetw(&tempdmap.mirrorDMap, f))
15320 {
15321 return 0;
15322 }
15323 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
15324 {
15325 return 0;
15326 }
15327 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
15328 {
15329 return 0;
15330 }
15331 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
15332 {
15333 return 0;
15334 }
15335 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
15336 {
15337 return 0;
15338 }
15339 }
15340 }
15341 DMaps[index] = tempdmap;
15342
15343 return 1;
15344 }
15345
15346 void dmap_rclick_func(int32_t index, int32_t x, int32_t y)
15347 {
15348 if(((unsigned)index)>MAXDMAPS)
15349 return;
15350
15351 NewMenu rcmenu {
15352 { "&Copy", [&]()
15353 {
15354 copiedDMap = DMaps[index];
15355 dmapcopied = 1;
15356 } },
15357 { "Paste", "&v", [&]()
15358 {
15359 DMaps[index] = copiedDMap;
15360 selectdmap_dlg[2].flags |= D_DIRTY;
15361 saved = false;
15362 }, 0, !dmapcopied },
15363 { "&Save", [&]()
15364 {
15365 if(!prompt_for_new_file_compat("Save DMAP(.zdmap)", "zdmap", NULL,datapath,false))
15366 return;
15367 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
15368 if(!f) return;
15369 writesomedmaps(f,index, index, MAXDMAPS);
15370 pack_fclose(f);
15371 } },
15372 { "&Load", [&]()
15373 {
15374 if(!prompt_for_existing_file_compat("Load DMAP(.zdmap)", "zdmap", NULL,datapath,false))
15375 return;
15376 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
15377 if(!f) return;
15378
15379 if (!readonedmap(f,index))
15380 {
15381 al_trace("Could not read from .zdmap packfile %s\n", temppath);
15382 jwin_alert("ZDMAP File: Error","Could not load the specified DMap.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
15383 }
15384
15385 pack_fclose(f);
15386 selectdmap_dlg[2].flags |= D_DIRTY; //Causes the dialogie list to refresh, updating the item name.
15387 saved = false;
15388 } },
15389 };
15390 rcmenu.pop(x, y);
15391 }
15392
15393
15394 int32_t onDmaps()
15395 {
15396 int32_t ret;
15397 char buf[40];
15398 dmapcopied = 0;
15399 dmap_list_size=MAXDMAPS;
15400 number_list_zero=true;
15401 selectdmap_dlg[0].dp2=get_zc_font(font_lfont);
15402 selectdmap_dlg[2].dp3 = (void *)&dmap_rclick_func;
15403 selectdmap_dlg[2].flags|=(D_USER<<1);
15404
15405 large_dialog(selectdmap_dlg);
15406
15407
15408
15409 ret=do_zqdialog(selectdmap_dlg,2);
15410 dmap* pSelectedDmap = 0;
15411
15412
15413
15414 while(ret!=4&&ret!=0)
15415 {
15416 int32_t d=selectdmap_dlg[2].d1;
15417
15418 if(ret==6) //copy
15419 {
15420 pSelectedDmap = &DMaps[d];
15421 }
15422 else if(ret==7 && pSelectedDmap != 0 ) //paste
15423 {
15424 if( pSelectedDmap != &DMaps[d] )
15425 {
15426 DMaps[d] = *pSelectedDmap;
15427 saved=false;
15428 }
15429 }
15430 else if(ret==5)
15431 {
15432 sprintf(buf,"Delete DMap %d?",d);
15433
15434 if(jwin_alert("Confirm Delete",buf,NULL,NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
15435 {
15436 reset_dmap(d);
15437 saved=false;
15438 }
15439 }
15440 else
15441 {
15442 call_editdmap_dialog(d);
15443 }
15444
15445 ret=do_zqdialog(selectdmap_dlg,2);
15446 }
15447
15448 return D_O_K;
15449 }
15450
15451 int32_t onRegions()
15452 {
15453 bool valid = false;
15454 for (int i = 0; i < MAPSCRS; i++)
15455 {
15456 if (Map.Scr(i)->is_valid())
15457 {
15458 valid = true;
15459 break;
15460 }
15461 }
15462
15463 if (valid)
15464 {
15465 call_edit_region_dialog(Map.getCurrMap());
15466 Map.regions_mark_dirty();
15467 }
15468 else
15469 {
15470 InfoDialog("Invalid maps", "There must be at least one valid screen in a map to configure regions").show();
15471 }
15472
15473 return D_O_K;
15474 }
15475
15476 int32_t onMidis()
15477 {
15478 stopMusic();
15479 MidiListerDialog().show();
15480 return D_O_K;
15481 }
15482
15483 static DIALOG editmusic_dlg[] =
15484 {
15485 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15486 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Music Specs", NULL, NULL },
15487 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15488 // 2
15489 { jwin_text_proc, 56, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Music:", NULL, NULL },
15490 { jwin_text_proc, 104, 94-16, 48, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15491 { jwin_text_proc, 56, 114, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15492 { jwin_edit_proc, 104, 114-4, 160, 16, vc(12), vc(1), 0, 0, 19, 0, NULL, NULL, NULL },
15493 { jwin_text_proc, 56, 124-4+12, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Volume:", NULL, NULL },
15494 { jwin_edit_proc, 120, 124-4+12-4, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
15495 // 8
15496 { jwin_check_proc, 176, 124+12-4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "Loop", NULL, NULL },
15497 // 9
15498 { jwin_button_proc, 50, 72-24, 57, 21, vc(14), vc(1), 'l', D_EXIT, 0, 0, (void *) "&Load", NULL, NULL },
15499 { jwin_iconbutton_proc, 116, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_STOPSQUARE, 0, NULL, NULL, NULL },
15500 { jwin_iconbutton_proc, 156, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT, 0, NULL, NULL, NULL },
15501 { jwin_iconbutton_proc, 196, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT2, 0, NULL, NULL, NULL },
15502 { jwin_iconbutton_proc, 236, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT3, 0, NULL, NULL, NULL },
15503 // 14
15504 { jwin_text_proc, 56, 134+4+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start:", NULL, NULL },
15505 { jwin_edit_proc, 112, 134+12, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15506 { jwin_text_proc, 176, 134+12+4, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop Start:", NULL, NULL },
15507 { jwin_edit_proc, 240, 134+12, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15508 { jwin_text_proc, 176, 144+12+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop End:", NULL, NULL },
15509 { jwin_edit_proc, 240, 144+12+12-4, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15510 // 20
15511 { jwin_text_proc, 176, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Position:", NULL, NULL },
15512 { jwin_text_proc, 217, 94-16, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15513 { jwin_text_proc, 176, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Length:", NULL, NULL },
15514 { jwin_text_proc, 216, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15515 { jwin_text_proc, 56, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Time:", NULL, NULL },
15516 { jwin_text_proc, 104, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15517 // 26
15518 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15519 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15520 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
15521 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15522 };
15523
15524 int32_t d_musiclist_proc(int32_t msg,DIALOG *d,int32_t c)
15525 {
15526 return jwin_list_proc(msg,d,c);
15527 }
15528
15529 12 static ListData enhancedmusic_list(enhancedmusiclist, &font);
15530
15531 static DIALOG selectmusic_dlg[] =
15532 {
15533 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15534 12 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Enhanced Music", NULL, NULL },
15535 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15536 12 { d_musiclist_proc, 31, 44, 164, (1+16)*8, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &enhancedmusic_list, NULL, NULL },
15537 12 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
15538 12 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
15539 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
15540 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15541 };
15542
15543 const char *warptypelist(int32_t index, int32_t *list_size)
15544 {
15545 if(index>=0)
15546 {
15547 if(index>=MAXWARPTYPES)
15548 index=MAXWARPTYPES-1;
15549
15550 return warptype_string[index];
15551 }
15552
15553 *list_size=MAXWARPTYPES;
15554 // *list_size=6;
15555 return NULL;
15556 }
15557
15558 const char *warpeffectlist(int32_t index, int32_t *list_size)
15559 {
15560 if(index>=0)
15561 {
15562 if(index>=MAXWARPEFFECTS)
15563 index=MAXWARPEFFECTS-1;
15564
15565 return warpeffect_string[index];
15566 }
15567
15568 *list_size=MAXWARPEFFECTS;
15569 return NULL;
15570 }
15571
15572 static int32_t warp1_list[] =
15573 {
15574 2,3,4,5,6,7,8,9,10,11,12,13,53,54,63,67,-1
15575 };
15576
15577 static int32_t warp2_list[] =
15578 {
15579 17,18,19,20,21,22,23,24,25,26,27,28,55,56,64,68,-1
15580 };
15581
15582 static int32_t warp3_list[] =
15583 {
15584 29,30,31,32,33,34,35,36,37,38,39,40,57,58,65,69,-1
15585 };
15586
15587 static int32_t warp4_list[] =
15588 {
15589 41,42,43,44,45,46,47,48,49,50,51,52,59,60,66,70,-1
15590 };
15591
15592 static TABPANEL warp_tabs[] =
15593 {
15594 // (text)
15595 { (char *)"A", D_SELECTED, warp1_list, 0, NULL },
15596 { (char *)"B", 0, warp2_list, 0, NULL },
15597 { (char *)"C", 0, warp3_list, 0, NULL },
15598 { (char *)"D", 0, warp4_list, 0, NULL },
15599 { NULL, 0, NULL, 0, NULL }
15600 };
15601
15602 int32_t onTileWarpIndex(int32_t index)
15603 {
15604 int32_t i=-1;
15605
15606 while(warp_tabs[++i].text != NULL)
15607 warp_tabs[i].flags = (i==index ? D_SELECTED : 0);
15608
15609 onTileWarp();
15610 return D_O_K;
15611 }
15612
15613 static char warpr_buf[10];
15614 const char *warprlist(int32_t index, int32_t *list_size)
15615 {
15616 if(index>=0)
15617 {
15618 bound(index,0,3);
15619 sprintf(warpr_buf,"%c",index+0x41);
15620 return warpr_buf;
15621 }
15622
15623 *list_size=4;
15624 return NULL;
15625 }
15626
15627 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t c);
15628
15629 12 static ListData warp_dlg_list(warptypelist, &font);
15630 12 static ListData warp_ret_list(warprlist, &font);
15631
15632 int32_t d_warpdestscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15633 {
15634 if(msg == MSG_START)
15635 {
15636 d->d1 = -1; //cached val
15637 d->d2 = -1; //cached dmap
15638 d->fg = 0; //cached 'force_16'
15639 }
15640 char* buf = (char*)d->dp;
15641 vector<DIALOG*>* dlgs = (vector<DIALOG*>*)d->dp2;
15642 int* dmap_ptr = (int*) d->dp3;
15643 if(!(buf && dmap_ptr))
15644 return D_O_K;
15645 bool is_overworld = ((DMaps[*dmap_ptr].type&dmfTYPE)==dmOVERW);
15646 int scrw = is_overworld ? 16 : 8, scrh = 9;
15647 const int max = 0x87;
15648 int bufval = zc_xtoi(buf);
15649 int val = vbound(bufval,0,max);
15650 auto& dm = DMaps[*dmap_ptr];
15651 auto val_offset = dm.xoff < 0 ? -dm.xoff : 0;
15652 bool force_16 = d->fg;
15653 if(!is_overworld)
15654 {
15655 if((val&0xF) >= 0x8)
15656 force_16 = true;
15657 else if((val&0xF) < val_offset && (val&0xF0) < 0x80)
15658 force_16 = true;
15659 }
15660 if(force_16) //can't bound, some quests need to warp out of bounds... -Em
15661 {
15662 scrw = 16; //just force show the larger grid instead
15663 val_offset = 0;
15664 }
15665
15666 int xscl = d->w/scrw;
15667 int yscl = d->h/scrh;
15668
15669 int ret = D_O_K;
15670 bool redraw = false;
15671 if(d->d1 != val)
15672 {
15673 redraw = true;
15674 d->d1 = val;
15675 }
15676 if(bufval != val)
15677 {
15678 redraw = true;
15679 sprintf(buf, "%X", val);
15680 }
15681 if(d->d2 != *dmap_ptr)
15682 {
15683 redraw = true;
15684 d->d2 = *dmap_ptr;
15685 }
15686 switch(msg)
15687 {
15688 case MSG_WANTFOCUS:
15689 ret = D_WANTFOCUS;
15690 break;
15691 case MSG_CLICK:
15692 {
15693 d->fg = force_16 ? 1 : 0;
15694 bool redraw2 = false;
15695 while(gui_mouse_b())
15696 {
15697 if(redraw2)
15698 {
15699 broadcast_dialog_message(MSG_DRAW, 0);
15700 redraw2 = false;
15701 }
15702 if(!d->fg && (gui_mouse_b()&2))
15703 {
15704 scrw = 16;
15705 xscl = d->w/scrw;
15706 yscl = d->h/scrh;
15707 val_offset = 0;
15708 d->fg = 1;
15709 redraw2 = true;
15710 }
15711 custom_vsync();
15712 if(!mouse_in_rect(d->x,d->y,d->w,d->h))
15713 continue;
15714 int mx = gui_mouse_x()-d->x, my = gui_mouse_y()-d->y;
15715 int y = vbound(my/yscl,0,scrh-1);
15716 auto offs = y==8 ? 0 : val_offset;
15717 int x = vbound(mx/xscl,offs,scrw-1);
15718 auto val2 = (y*16)+x;
15719 if(val2 > max) //out of bounds in the bottom-right
15720 continue;
15721 val = val2;
15722 if(d->d1 != val)
15723 {
15724 d->d1 = val;
15725 sprintf(buf, "%02X", val);
15726 redraw2 = true;
15727 }
15728 }
15729 redraw = true;
15730 d->fg = 0;
15731 break;
15732 }
15733 case MSG_DRAW:
15734 {
15735 rectfill(screen,d->x,d->y,d->x+d->w-1,d->y+d->h-1,jwin_pal[jcBOX]);
15736 jwin_draw_frame(screen, d->x-2, d->y-2, d->w+4, d->h+4, FR_MENU);
15737 for(int yind = 0; yind < scrh; ++yind)
15738 {
15739 auto gr = (yind < 8 ? dm.grid[yind] : 0);
15740 for(int xind = (yind == 8 ? 0 : val_offset); xind < scrw; ++xind)
15741 {
15742 int screen_index = xind+(yind*16);
15743 if(screen_index > max)
15744 continue;
15745 int fr = FR_MENU;
15746 if(screen_index == d->d1)
15747 fr = FR_GREEN;
15748 else if(!is_overworld && xind < 8 && (gr&(1<<(8-xind-1))))
15749 fr = FR_MENU_INV;
15750 jwin_draw_frame(screen, d->x+(xind*xscl), d->y+(yind*yscl), xscl, yscl, fr);
15751 }
15752 }
15753 break;
15754 }
15755 case MSG_XCHAR:
15756 {
15757 bool on_80 = (val&0xF0) == 0x80;
15758 switch(c>>8)
15759 {
15760 case KEY_UP:
15761 if((val&0xF0) && !(val_offset && on_80 && (val&0xF) < val_offset))
15762 {
15763 val -= 0x10;
15764 redraw = true;
15765 }
15766 ret |= D_USED_CHAR;
15767 break;
15768 case KEY_DOWN:
15769 if((val&0xF0) < ((val&0xF) < 0x8 ? 0x80 : 0x70))
15770 {
15771 val += 0x10;
15772 redraw = true;
15773 }
15774 ret |= D_USED_CHAR;
15775 break;
15776 case KEY_LEFT:
15777 if((val&0xF) > (on_80 ? 0 : val_offset))
15778 {
15779 --val;
15780 redraw = true;
15781 }
15782 ret |= D_USED_CHAR;
15783 break;
15784 case KEY_RIGHT:
15785 if((val&0xF) < scrw-1 && val < 0x87)
15786 {
15787 ++val;
15788 redraw = true;
15789 }
15790 ret |= D_USED_CHAR;
15791 break;
15792 }
15793 if(redraw)
15794 sprintf(buf, "%02X", val);
15795 break;
15796 }
15797 }
15798 if(redraw)
15799 {
15800 if(msg == MSG_IDLE)
15801 broadcast_dialog_message(MSG_DRAW,0);
15802 else
15803 {
15804 d->d1 = d->d2 = -1;
15805 object_message(d,MSG_IDLE,0);
15806 }
15807 }
15808
15809 return ret;
15810 }
15811
15812 int32_t tilewarpdmapxy[6] = {170,38,170,18,170,27};
15813 static DIALOG tilewarp_dlg[] =
15814 {
15815 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15816 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15817 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15818 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15819 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15820 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15821 //5
15822 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15823 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15824 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15825 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15826 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15827 //10
15828 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15829 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15830 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15831 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15832 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15833 //15
15834 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15835 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15836 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15837 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15838 };
15839
15840 int32_t sidewarpdmapxy[6] = {170,38,170,18,170,27};
15841 static DIALOG sidewarp_dlg[] =
15842 {
15843 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15844 12 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15845 12 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15846 12 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15847 12 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15848 12 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15849 //5
15850 12 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15851 12 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15852 12 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15853 12 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15854 12 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15855 //10
15856 12 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15857 12 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15858 12 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15859 12 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15860 12 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15861 //15
15862 12 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15863 12 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15864 12 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15865 // 18
15866 12 { d_wflag_proc, 18, 17, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15867 12 { d_wflag_proc, 18, 47, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15868 // 20
15869 12 { d_wflag_proc, 8, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15870 12 { d_wflag_proc, 37, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15871
15872 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15873 };
15874
15875 int32_t warpringxy[6] = {170,38,170,18,170,27};
15876 static DIALOG warpring_warp_dlg[] =
15877 {
15878 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15879 12 { jwin_win_proc, 0, 0, 302, 145, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15880 12 { jwin_rtext_proc, 57, 25, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15881 12 { jwin_rtext_proc, 57, 46, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15882 12 { d_dropdmaplist_proc, 59, 19, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, warpringxy },
15883 12 { jwin_hexedit_proc, 59, 39, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15884 // 5
15885 12 { jwin_button_proc, 61, 115, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15886 12 { jwin_button_proc, 121, 115, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15887 12 { jwin_button_proc, 181, 115, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15888 12 { d_warpdestscrsel_proc, 90, 39, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15889
15890 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15891 };
15892
15893 // Side warp flag procedure
15894 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t)
15895 {
15896 int32_t ret = D_O_K;
15897 switch(msg)
15898 {
15899 case MSG_DRAW:
15900 {
15901 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15902
15903 if(d->d1==1)
15904 {
15905 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15906 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15907
15908 if(d->flags&D_SELECTED)
15909 {
15910 int32_t e=d->d2&3;
15911
15912 if(d->w>d->h)
15913 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15914 else
15915 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15916 }
15917
15918 }
15919 else
15920 {
15921 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15922 }
15923 }
15924 break;
15925
15926 case MSG_CLICK:
15927 {
15928 if(d->flags & D_DISABLED)
15929 return D_O_K;
15930 bool rclick = gui_mouse_b() & 2;
15931 if(d->d1==1)
15932 {
15933 if(!(d->flags&D_SELECTED))
15934 {
15935 d->flags |= D_SELECTED;
15936 d->d2 &= 0x80;
15937 if (rclick)
15938 d->d2 |= 3;
15939 }
15940 else
15941 {
15942 if((d->d2&3) == (rclick?0:3))
15943 {
15944 d->flags ^= D_SELECTED;
15945 d->d2 &= 0x80;
15946 }
15947 else
15948 {
15949 int32_t f = d->d2&3;
15950 d->d2 &= 0x80;
15951 f += rclick ? -1 : 1;
15952 d->d2 |= f;
15953 }
15954 }
15955 }
15956 else
15957 {
15958 d->flags^=D_SELECTED;
15959 }
15960
15961 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15962
15963 if(d->d1==1)
15964 {
15965 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15966 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15967
15968 if(d->flags&D_SELECTED)
15969 {
15970 int32_t e=d->d2&3;
15971
15972 if(d->w>d->h)
15973 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15974 else
15975 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15976 }
15977 }
15978 else
15979 {
15980 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15981 }
15982
15983
15984 while(gui_mouse_b())
15985 {
15986 /* do nothing */
15987 rest(1);
15988 }
15989 ret = D_REDRAWME;
15990 }
15991 break;
15992 }
15993
15994 return ret;
15995 }
15996
15997 int32_t d_dmapscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15998 {
15999 //these are here to bypass compiler warnings about unused arguments
16000 c=c;
16001
16002 int32_t ret = D_O_K;
16003
16004 switch(msg)
16005 {
16006 case MSG_CLICK:
16007 sprintf((char*)((d+2)->dp),"%X%X",vbound((gui_mouse_y()-d->y)/4,0,7),vbound((gui_mouse_x()-d->x)/(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?4:8),0,(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?15:7)));
16008 object_message(d+2, MSG_DRAW, 0);
16009 break;
16010 }
16011
16012 return ret;
16013 }
16014
16015 int32_t warpdestsel_x=-1;
16016 int32_t warpdestsel_y=-1;
16017 int32_t warpdestmap=-1;
16018 int32_t warpdestscr=-1;
16019
16020 int32_t jwin_minibutton_proc(int32_t msg,DIALOG *d,int32_t c)
16021 {
16022 switch(msg)
16023 {
16024 case MSG_DRAW:
16025 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, false);
16026 return D_O_K;
16027 break;
16028 }
16029
16030 return jwin_button_proc(msg,d,c);
16031 }
16032
16033 int32_t d_triggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
16034 {
16035 static BITMAP *dummy=create_bitmap_ex(8, 1, 1);
16036
16037 switch(msg)
16038 {
16039 case MSG_START:
16040 d->w=gui_textout_ln(dummy, font, (uint8_t *)d->dp, 0, 0, jwin_pal[jcMEDDARK], -1, 0)+4;
16041 d->h=text_height(font)+5;
16042 break;
16043
16044 case MSG_GOTFOCUS:
16045 d->flags&=~D_GOTFOCUS;
16046 break;
16047
16048 }
16049
16050 return jwin_minibutton_proc(msg,d,c);
16051 }
16052
16053 int32_t d_alltriggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
16054 {
16055 DIALOG *temp_d;
16056 int32_t ret=d_triggerbutton_proc(msg,d,c);
16057
16058 switch(msg)
16059 {
16060 case MSG_CLICK:
16061 temp_d=d-1;
16062
16063 while(temp_d->proc==d_triggerbutton_proc)
16064 {
16065 temp_d->flags&=~D_SELECTED;
16066 temp_d->flags|=D_DIRTY;
16067
16068 if(d->flags&D_SELECTED)
16069 {
16070 temp_d->flags|=D_SELECTED;
16071 }
16072
16073 --temp_d;
16074 }
16075
16076 break;
16077 }
16078
16079 return ret;
16080 }
16081
16082 int32_t d_ticsedit_proc(int32_t msg,DIALOG *d,int32_t c)
16083 {
16084 int32_t ret = jwin_edit_proc(msg,d,c);
16085
16086 if(msg==MSG_DRAW)
16087 {
16088 int32_t tics=vbound(atoi((char*)d->dp),0,65535);
16089 sprintf((char*)(d+1)->dp,"%s %s",ticksstr(tics),tics==0?"(No Timed Warp)":" ");
16090 object_message(d+1,MSG_DRAW,c);
16091 }
16092
16093 return ret;
16094 }
16095
16096 12 static ListData warp_effect_list(warpeffectlist,&font);
16097
16098 struct tw_data
16099 {
16100 int twscr[4], twtype[4], twdmap[4], wret[4];
16101 byte oflags;
16102 optional<uint> loaded;
16103
16104 tw_data(mapscr* scr) {load_scr(scr);}
16105 void load_scr(mapscr* scr)
16106 {
16107 oflags = scr->tilewarpoverlayflags;
16108 for(int q = 0; q < 4; ++q)
16109 {
16110 twscr[q] = scr->tilewarpscr[q];
16111 twtype[q] = scr->tilewarptype[q];
16112 twdmap[q] = scr->tilewarpdmap[q];
16113 wret[q] = (scr->warpreturnc >> (2*q))&3;
16114 }
16115 loaded.reset();
16116 }
16117 void save_scr(mapscr* scr)
16118 {
16119 saved=false;
16120 scr->tilewarpoverlayflags = oflags;
16121 scr->warpreturnc = scr->warpreturnc & 0xFF00;
16122 for(int q = 0; q < 4; ++q)
16123 {
16124 scr->tilewarpscr[q] = twscr[q];
16125 scr->tilewarptype[q] = twtype[q];
16126 scr->tilewarpdmap[q] = twdmap[q];
16127 scr->warpreturnc |= wret[q] << (2*q);
16128 }
16129 }
16130
16131 void load(uint ind)
16132 {
16133 if(ind >= 4) return;
16134 loaded = ind;
16135 tilewarp_dlg[4].d1 = twtype[ind];
16136 tilewarp_dlg[5].d1 = twdmap[ind];
16137 char* buf = (char*)tilewarp_dlg[6].dp;
16138 sprintf(buf,"%02X",twscr[ind]);
16139 tilewarp_dlg[11].d1 = wret[ind];
16140 SETFLAG(tilewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16141 for(int q = 0; q < 4; ++q)
16142 SETFLAG(tilewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16143 }
16144 void save(uint ind)
16145 {
16146 if(ind >= 4) return;
16147 twtype[ind] = tilewarp_dlg[4].d1;
16148 twdmap[ind] = tilewarp_dlg[5].d1;
16149 char* buf = (char*)tilewarp_dlg[6].dp;
16150 twscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16151 wret[ind] = tilewarp_dlg[11].d1;
16152 set_bit(&oflags, ind, tilewarp_dlg[12].flags & D_SELECTED);
16153 }
16154 void save()
16155 {
16156 if(loaded)
16157 save(*loaded);
16158 }
16159 void swap(uint ind)
16160 {
16161 if(ind >= 4) return;
16162 if(loaded)
16163 {
16164 save(*loaded);
16165 if(*loaded == ind)
16166 return;
16167 }
16168 load(ind);
16169 }
16170 };
16171 int32_t onTileWarp()
16172 {
16173 restore_mouse();
16174 tilewarp_dlg[0].dp=(void *) "Tile Warp";
16175 tilewarp_dlg[0].dp2=get_zc_font(font_lfont);
16176
16177 mapscr* mptr = Map.CurrScr();
16178 char buf[10];
16179 tilewarp_dlg[6].dp=buf;
16180 tilewarp_dlg[13].dp = buf;
16181 tilewarp_dlg[13].dp3 = &tilewarp_dlg[5].d1;
16182
16183 vector<DIALOG*> dlgs;
16184 dlgs.push_back(&tilewarp_dlg[5]);
16185 dlgs.push_back(&tilewarp_dlg[6]);
16186 tilewarp_dlg[13].dp2 = &dlgs;
16187
16188 tw_data data(mptr);
16189 data.load(0);
16190
16191 dmap_list_size=MAXDMAPS;
16192 dmap_list_zero=true;
16193
16194 large_dialog(tilewarp_dlg);
16195
16196 bool running = true;
16197 int ret;
16198 do
16199 {
16200 ret = do_zqdialog(tilewarp_dlg,-1);
16201 switch(ret)
16202 {
16203 // OK, GO
16204 case 7: case 8:
16205 running = false;
16206 data.save();
16207 data.save_scr(mptr);
16208 refresh(rMENU);
16209 break;
16210 //Cancel
16211 case 9:
16212 running = false;
16213 break;
16214 //A,B,C,D
16215 case 14: case 15: case 16: case 17:
16216 data.swap(ret-14);
16217 break;
16218 }
16219 }
16220 while(running);
16221
16222 if(ret==8) //GO
16223 {
16224 int32_t index = *data.loaded;
16225
16226 FlashWarpSquare = -1;
16227 int32_t tm = Map.getCurrMap();
16228 int32_t ts = Map.getCurrScr();
16229 int32_t thistype = mptr->tilewarptype[index];
16230 Map.dowarp(0,index);
16231
16232 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtCAVE && thistype != wtSCROLL)
16233 {
16234 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(index*2))&3;
16235 FlashWarpClk = 32;
16236 }
16237
16238 refresh(rALL);
16239 }
16240
16241 return D_O_K;
16242 }
16243
16244 struct sw_data
16245 {
16246 int swscr[4], swtype[4], swdmap[4], wret[4];
16247 byte oflags;
16248 optional<uint> loaded;
16249
16250 sw_data(mapscr* scr) {load_scr(scr);}
16251 void load_scr(mapscr* scr)
16252 {
16253 oflags = scr->sidewarpoverlayflags;
16254 for(int q = 0; q < 4; ++q)
16255 {
16256 swscr[q] = scr->sidewarpscr[q];
16257 swtype[q] = scr->sidewarptype[q];
16258 swdmap[q] = scr->sidewarpdmap[q];
16259 wret[q] = (scr->warpreturnc >> (2*(q+4)))&3;
16260 }
16261 loaded.reset();
16262
16263 for(int32_t i=0; i<4; i++)
16264 {
16265 sidewarp_dlg[18+i].d2 = 0x80;
16266 if(scr->flags2&(1<<i))
16267 {
16268 sidewarp_dlg[18+i].flags = D_SELECTED ;
16269 sidewarp_dlg[18+i].d2 |= (scr->sidewarpindex>>(2*i))&3;
16270 }
16271 else
16272 {
16273 sidewarp_dlg[18+i].flags = 0;
16274 }
16275 }
16276 }
16277 void save_scr(mapscr* scr)
16278 {
16279 saved=false;
16280 scr->sidewarpoverlayflags = oflags;
16281 scr->warpreturnc = scr->warpreturnc & 0x00FF;
16282 for(int q = 0; q < 4; ++q)
16283 {
16284 scr->sidewarpscr[q] = swscr[q];
16285 scr->sidewarptype[q] = swtype[q];
16286 scr->sidewarpdmap[q] = swdmap[q];
16287 scr->warpreturnc |= wret[q] << (2*(q+4));
16288 }
16289
16290 scr->flags2 &= ~0xF;
16291 scr->sidewarpindex = 0;
16292 for(int32_t i=0; i<4; i++)
16293 {
16294 if(sidewarp_dlg[18+i].flags & D_SELECTED)
16295 scr->flags2 |= 1<<i;
16296 scr->sidewarpindex |= (sidewarp_dlg[18+i].d2&3) << (i*2);
16297 }
16298 }
16299
16300 void load(uint ind)
16301 {
16302 if(ind >= 4) return;
16303 loaded = ind;
16304 sidewarp_dlg[4].d1 = swtype[ind];
16305 sidewarp_dlg[5].d1 = swdmap[ind];
16306 char* buf = (char*)sidewarp_dlg[6].dp;
16307 sprintf(buf,"%02X",swscr[ind]);
16308 sidewarp_dlg[11].d1 = wret[ind];
16309 SETFLAG(sidewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16310 for(int q = 0; q < 4; ++q)
16311 SETFLAG(sidewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16312 }
16313 void save(uint ind)
16314 {
16315 if(ind >= 4) return;
16316 swtype[ind] = sidewarp_dlg[4].d1;
16317 swdmap[ind] = sidewarp_dlg[5].d1;
16318 char* buf = (char*)sidewarp_dlg[6].dp;
16319 swscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16320 wret[ind] = sidewarp_dlg[11].d1;
16321 set_bit(&oflags, ind, sidewarp_dlg[12].flags & D_SELECTED);
16322 }
16323 void save()
16324 {
16325 if(loaded)
16326 save(*loaded);
16327 }
16328 void swap(uint ind)
16329 {
16330 if(ind >= 4) return;
16331 if(loaded)
16332 {
16333 save(*loaded);
16334 if(*loaded == ind)
16335 return;
16336 }
16337 load(ind);
16338 }
16339 };
16340 int32_t onSideWarp()
16341 {
16342 restore_mouse();
16343 sidewarp_dlg[0].dp=(void *) "Side Warp";
16344 sidewarp_dlg[0].dp2=get_zc_font(font_lfont);
16345
16346 mapscr* mptr = Map.CurrScr();
16347 char buf[10];
16348 sidewarp_dlg[6].dp=buf;
16349 sidewarp_dlg[13].dp = buf;
16350 sidewarp_dlg[13].dp3 = &sidewarp_dlg[5].d1;
16351
16352 vector<DIALOG*> dlgs;
16353 dlgs.push_back(&sidewarp_dlg[5]);
16354 dlgs.push_back(&sidewarp_dlg[6]);
16355 sidewarp_dlg[13].dp2 = &dlgs;
16356
16357 sw_data data(mptr);
16358 data.load(0);
16359
16360 dmap_list_size=MAXDMAPS;
16361 dmap_list_zero=true;
16362
16363 large_dialog(sidewarp_dlg);
16364
16365 bool running = true;
16366 int ret;
16367 do
16368 {
16369 ret = do_zqdialog(sidewarp_dlg,-1);
16370 switch(ret)
16371 {
16372 // OK, GO
16373 case 7: case 8:
16374 running = false;
16375 data.save();
16376 data.save_scr(mptr);
16377 refresh(rMENU);
16378 break;
16379 //Cancel
16380 case 9:
16381 running = false;
16382 break;
16383 //A,B,C,D
16384 case 14: case 15: case 16: case 17:
16385 data.swap(ret-14);
16386 break;
16387 }
16388 }
16389 while(running);
16390
16391 if(ret==8) //GO
16392 {
16393 int32_t index = *data.loaded;
16394
16395 FlashWarpSquare = -1;
16396 int32_t tm = Map.getCurrMap();
16397 int32_t ts = Map.getCurrScr();
16398
16399 int32_t thistype = mptr->sidewarptype[index];
16400 Map.dowarp(1,index);
16401
16402 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtSCROLL)
16403 {
16404 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(8+index*2))&3;
16405 FlashWarpClk = 0x20;
16406 }
16407
16408 refresh(rALL);
16409 }
16410
16411 return D_O_K;
16412 }
16413
16414
16415
16416 const char *dirlist(int32_t index, int32_t *list_size)
16417 {
16418 if(index>=0)
16419 {
16420 if(index>3)
16421 index=3;
16422
16423 return mazedirstr[index];
16424 }
16425
16426 *list_size=4;
16427 return NULL;
16428 }
16429
16430 12 static ListData path_dlg_list(dirlist, &font);
16431
16432 static const char *wipestr[] = {"None", "Circle", "Oval", "Triangle", "SMAS", "Fade Black"};
16433 // enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
16434 const char *wipelist(int32_t index, int32_t *list_size)
16435 {
16436 if(index>=0)
16437 {
16438 if(index>5)
16439 index=5;
16440
16441 return wipestr[index];
16442 }
16443
16444 *list_size=6;
16445 return NULL;
16446 }
16447
16448 12 static ListData wipe_effect_dlg_list(wipelist, &font);
16449
16450 static DIALOG path_dlg[] =
16451 {
16452 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16453 12 { jwin_win_proc, 80, 57, 161, 182, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Maze Path", NULL, NULL },
16454 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16455 12 { jwin_text_proc, 94, 106, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16456 12 { jwin_text_proc, 94, 124, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16457 12 { jwin_text_proc, 94, 142, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16458 12 { jwin_text_proc, 94, 160, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "4th", NULL, NULL },
16459 12 { jwin_text_proc, 94, 178, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Exit", NULL, NULL },
16460 12 { jwin_text_proc, 94, 196, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Wipe effect", NULL, NULL },
16461 12 { jwin_droplist_proc, 140, 102, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16462 12 { jwin_droplist_proc, 140, 120, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16463 12 { jwin_droplist_proc, 140, 138, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16464 12 { jwin_droplist_proc, 140, 156, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16465 12 { jwin_droplist_proc, 140, 174, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16466 12 { jwin_droplist_proc, 140, 192, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &wipe_effect_dlg_list, NULL, NULL },
16467 12 { jwin_button_proc, 90, 212, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16468 12 { jwin_button_proc, 170, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16469 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
16470 12 { jwin_text_proc, 87, 82, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "A Lost Woods-style maze screen", NULL, NULL },
16471 12 { jwin_text_proc, 87, 92, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "with a normal and secret exit.", NULL, NULL },
16472 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16473 };
16474
16475 int32_t onPath()
16476 {
16477 restore_mouse();
16478 path_dlg[0].dp2=get_zc_font(font_lfont);
16479
16480 for(int32_t i=0; i<4; i++)
16481 path_dlg[i+8].d1 = Map.CurrScr()->path[i];
16482
16483 path_dlg[12].d1 = Map.CurrScr()->exitdir;
16484 path_dlg[13].d1 = Map.CurrScr()->maze_transition_wipe;
16485
16486 large_dialog(path_dlg);
16487
16488 int32_t ret;
16489
16490 do
16491 {
16492 ret=do_zqdialog(path_dlg,8);
16493
16494 if(ret==14)
16495 {
16496 for(int32_t i=0; i<4; i++)
16497 {
16498 if(path_dlg[i+8].d1 == path_dlg[12].d1)
16499 {
16500 if(jwin_alert("Exit Problem","One of the path's directions is","also the normal Exit direction! Continue?",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==2)
16501 ret = -1;
16502
16503 break;
16504 }
16505 }
16506 }
16507 }
16508 while(ret == -1);
16509
16510 if(ret==14)
16511 {
16512 saved=false;
16513
16514 for(int32_t i=0; i<4; i++)
16515 Map.CurrScr()->path[i] = path_dlg[i+8].d1;
16516
16517 Map.CurrScr()->exitdir = path_dlg[12].d1;
16518 Map.CurrScr()->maze_transition_wipe = path_dlg[13].d1;
16519
16520 if(!(Map.CurrScr()->flags&fMAZE))
16521 if(jwin_alert("Screen Flag","Turn on the 'Use Maze Path' Screen Flag?","(Go to 'Screen Data' to turn it off.)",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==1)
16522 Map.CurrScr()->flags |= fMAZE;
16523 }
16524
16525 refresh(rMAP+rMENU);
16526 return D_O_K;
16527 }
16528
16529
16530
16531 static DIALOG editinfo_dlg[] =
16532 {
16533 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16534 12 { jwin_win_proc, 0, 10, 208, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16535 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16536 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16537 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16538 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16539 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16540 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16541 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16542 // 8
16543 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16544 12 { d_ndroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16545 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16546 12 { d_ndroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16547 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16548 12 { d_ndroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16549 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16550 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16551 // 16
16552 12 { jwin_button_proc, 34, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16553 12 { jwin_button_proc, 114, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16554 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16555 };
16556
16557 void EditInfoType(int32_t index)
16558 {
16559 char ps1[6],ps2[6],ps3[6];
16560 char infoname[33];
16561 char caption[40];
16562
16563 int32_t str1, str2, str3;
16564
16565 sprintf(caption,"Info Data %d",index);
16566 editinfo_dlg[0].dp = caption;
16567 editinfo_dlg[0].dp2 = get_zc_font(font_lfont);
16568
16569 sprintf(ps1,"%d",QMisc.info[index].price[0]);
16570 sprintf(ps2,"%d",QMisc.info[index].price[1]);
16571 sprintf(ps3,"%d",QMisc.info[index].price[2]);
16572 strncpy(infoname,QMisc.info[index].name,32);
16573 infoname[32] = 0;
16574 editinfo_dlg[8].dp = ps1;
16575 editinfo_dlg[10].dp = ps2;
16576 editinfo_dlg[12].dp = ps3;
16577 editinfo_dlg[15].dp = infoname;
16578 str1 = QMisc.info[index].str[0];
16579 str2 = QMisc.info[index].str[1];
16580 str3 = QMisc.info[index].str[2];
16581 editinfo_dlg[9].d1 = MsgStrings[str1].listpos;
16582 editinfo_dlg[11].d1 = MsgStrings[str2].listpos;
16583 editinfo_dlg[13].d1 = MsgStrings[str3].listpos;
16584 ListData msgs_list(msgslist2, &a4fonts[font_lfont_l]);
16585 editinfo_dlg[9].dp =
16586 editinfo_dlg[11].dp =
16587 editinfo_dlg[13].dp = (void *) &msgs_list;
16588
16589 large_dialog(editinfo_dlg);
16590
16591 int32_t ret = do_zqdialog(editinfo_dlg,-1);
16592
16593 if(ret==16)
16594 {
16595 saved=false;
16596 QMisc.info[index].price[0] = vbound(atoi(ps1), 0, 65535);
16597 QMisc.info[index].price[1] = vbound(atoi(ps2), 0, 65535);
16598 QMisc.info[index].price[2] = vbound(atoi(ps3), 0, 65535);
16599 strncpy(QMisc.info[index].name,infoname,32);
16600 str1 = editinfo_dlg[9].d1;
16601 str2 = editinfo_dlg[11].d1;
16602 str3 = editinfo_dlg[13].d1;
16603 QMisc.info[index].str[0] = msg_at_pos(str1);
16604 QMisc.info[index].str[1] = msg_at_pos(str2);
16605 QMisc.info[index].str[2] = msg_at_pos(str3);
16606
16607 //move 0s to the end
16608 word swaptmp;
16609
16610 if(QMisc.info[index].str[0] == 0)
16611 {
16612 //possibly permute the infos
16613 if(QMisc.info[index].str[1] != 0)
16614 {
16615 //swap
16616 swaptmp = QMisc.info[index].str[0];
16617 QMisc.info[index].str[0] = QMisc.info[index].str[1];
16618 QMisc.info[index].str[1] = swaptmp;
16619 swaptmp = QMisc.info[index].price[0];
16620 QMisc.info[index].price[0] = QMisc.info[index].price[1];
16621 QMisc.info[index].price[1] = swaptmp;
16622 }
16623 else if(QMisc.info[index].str[2] != 0)
16624 {
16625 //move info 0 to 1, 1 to 2, and 2 to 0
16626 swaptmp = QMisc.info[index].str[0];
16627 QMisc.info[index].str[0] = QMisc.info[index].str[2];
16628 QMisc.info[index].str[2] = QMisc.info[index].str[1];
16629 QMisc.info[index].str[1] = swaptmp;
16630 swaptmp = QMisc.info[index].price[0];
16631 QMisc.info[index].price[0] = QMisc.info[index].price[2];
16632 QMisc.info[index].price[2] = QMisc.info[index].price[1];
16633 QMisc.info[index].price[1] = swaptmp;
16634 }
16635 }
16636
16637 if(QMisc.info[index].str[1] == 0 && QMisc.info[index].str[2] != 0)
16638 //swap
16639 {
16640 swaptmp = QMisc.info[index].str[1];
16641 QMisc.info[index].str[1] = QMisc.info[index].str[2];
16642 QMisc.info[index].str[2] = swaptmp;
16643 swaptmp = QMisc.info[index].price[1];
16644 QMisc.info[index].price[1] = QMisc.info[index].price[2];
16645 QMisc.info[index].price[2] = swaptmp;
16646 }
16647 }
16648 }
16649
16650 int32_t onInfoTypes()
16651 {
16652 info_list_size = 256;
16653
16654 int32_t index = select_data("Info Types",0,infolist,"Edit","Done",get_zc_font(font_lfont));
16655
16656 while(index!=-1)
16657 {
16658 EditInfoType(index);
16659
16660 index = select_data("Info Types",index,infolist,"Edit","Done",get_zc_font(font_lfont));
16661 }
16662
16663 return D_O_K;
16664 }
16665
16666
16667
16668 //This dialogie is self-contained, and does not use dialogue control numbers in a separate array to generate its fields.
16669 static DIALOG editshop_dlg[] =
16670 {
16671 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16672 12 { jwin_win_proc, 0, 10, 221, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16673 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16674 12 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16675 12 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16676 12 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16677 12 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16678 12 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16679 12 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16680 // 8
16681 12 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16682 12 { d_nidroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16683 12 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16684 12 { d_nidroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16685 12 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16686 12 { d_nidroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16687 12 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16688 12 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16689
16690 // 16
16691 12 { jwin_button_proc, 40, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16692 12 { jwin_button_proc, 121, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16693 //18
16694 12 { jwin_text_proc, 130, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16695 12 { jwin_text_proc, 130, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16696 12 { jwin_text_proc, 130, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16697 // 21
16698 12 { jwin_edit_proc, 155, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16699 12 { jwin_edit_proc, 155, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16700 12 { jwin_edit_proc, 155, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16701
16702 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16703 };
16704
16705 void EditShopType(int32_t index)
16706 {
16707
16708 build_bii_list(true);
16709 char ps1[6],ps2[6],ps3[6];
16710 char info1[6],info2[6],info3[6];
16711 char shopname[32];
16712 char caption[40];
16713
16714 sprintf(caption,"Shop Data %d",index);
16715 editshop_dlg[0].dp = caption;
16716 editshop_dlg[0].dp2=get_zc_font(font_lfont);
16717
16718 sprintf(ps1,"%d",QMisc.shop[index].price[0]);
16719 sprintf(ps2,"%d",QMisc.shop[index].price[1]);
16720 sprintf(ps3,"%d",QMisc.shop[index].price[2]);
16721
16722 sprintf(info1,"%d",QMisc.shop[index].str[0]);
16723 sprintf(info2,"%d",QMisc.shop[index].str[1]);
16724 sprintf(info3,"%d",QMisc.shop[index].str[2]);
16725
16726 sprintf(shopname,"%s",QMisc.shop[index].name);
16727 editshop_dlg[8].dp = ps1;
16728 editshop_dlg[10].dp = ps2;
16729 editshop_dlg[12].dp = ps3;
16730 editshop_dlg[15].dp = shopname;
16731
16732 editshop_dlg[21].dp = info1;
16733 editshop_dlg[22].dp = info2;
16734 editshop_dlg[23].dp = info3;
16735
16736 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16737
16738 editshop_dlg[9].dp = (void *) &item_list;
16739 editshop_dlg[11].dp = (void *) &item_list;
16740 editshop_dlg[13].dp = (void *) &item_list;
16741
16742 for(int32_t i=0; i<3; ++i)
16743 {
16744 if(QMisc.shop[index].hasitem[i])
16745 {
16746 for(int32_t j=0; j<bii_cnt; j++)
16747 {
16748 if(bii[j].i == QMisc.shop[index].item[i])
16749 {
16750 editshop_dlg[9+(i<<1)].d1 = j;
16751 }
16752 }
16753 }
16754 else
16755 {
16756 editshop_dlg[9+(i<<1)].d1 = -2;
16757 }
16758 }
16759
16760 large_dialog(editshop_dlg);
16761
16762 int32_t ret = do_zqdialog(editshop_dlg,-1);
16763
16764 if(ret==16)
16765 {
16766 saved=false;
16767 QMisc.shop[index].price[0] = vbound(atoi(ps1), 0, 65535);
16768 QMisc.shop[index].price[1] = vbound(atoi(ps2), 0, 65535);
16769 QMisc.shop[index].price[2] = vbound(atoi(ps3), 0, 65535);
16770
16771 QMisc.shop[index].str[0] = vbound(atoi(info1), 0, 65535);
16772 QMisc.shop[index].str[1] = vbound(atoi(info2), 0, 65535);
16773 QMisc.shop[index].str[2] = vbound(atoi(info3), 0, 65535);
16774
16775 snprintf(QMisc.shop[index].name, 32, "%s",shopname);
16776
16777 for(int32_t i=0; i<3; ++i)
16778 {
16779 if(bii[editshop_dlg[9+(i<<1)].d1].i == -2)
16780 {
16781 QMisc.shop[index].hasitem[i] = 0;
16782 QMisc.shop[index].item[i] = 0;
16783 QMisc.shop[index].price[i] = 0;
16784 }
16785 else
16786 {
16787 QMisc.shop[index].hasitem[i] = 1;
16788 QMisc.shop[index].item[i] = bii[editshop_dlg[9+(i<<1)].d1].i;
16789 }
16790 }
16791
16792 //filter all the 0 items to the end (yeah, bubble sort; sue me)
16793 word swaptmp;
16794
16795 for(int32_t j=0; j<3-1; j++)
16796 {
16797 for(int32_t k=0; k<2-j; k++)
16798 {
16799 if(QMisc.shop[index].hasitem[k]==0)
16800 {
16801 swaptmp = QMisc.shop[index].item[k];
16802 QMisc.shop[index].item[k] = QMisc.shop[index].item[k+1];
16803 QMisc.shop[index].item[k+1] = swaptmp;
16804 swaptmp = QMisc.shop[index].price[k];
16805 QMisc.shop[index].price[k] = QMisc.shop[index].price[k+1];
16806 QMisc.shop[index].price[k+1] = swaptmp;
16807 swaptmp = QMisc.shop[index].hasitem[k];
16808 QMisc.shop[index].hasitem[k] = QMisc.shop[index].item[k+1];
16809 QMisc.shop[index].hasitem[k+1] = swaptmp;
16810 }
16811 }
16812 }
16813 }
16814 }
16815
16816 int32_t onShopTypes()
16817 {
16818 shop_list_size = 256;
16819
16820 int32_t index = select_data("Shop Types",0,shoplist,"Edit","Done",get_zc_font(font_lfont));
16821
16822 while(index!=-1)
16823 {
16824 EditShopType(index);
16825 index = select_data("Shop Types",index,shoplist,"Edit","Done",get_zc_font(font_lfont));
16826 }
16827
16828 return D_O_K;
16829 }
16830
16831 void call_bottle_dlg(int32_t index);
16832 int32_t onBottleTypes()
16833 {
16834 bottle_list_size = 64;
16835 int32_t index = 0;
16836
16837 while(index > -1)
16838 {
16839 index = select_data("Bottle Types", index, bottlelist, "Edit", "Done", get_zc_font(font_lfont));
16840 if(index > -1)
16841 call_bottle_dlg(index);
16842 }
16843
16844 return D_O_K;
16845 }
16846
16847 void call_bottleshop_dlg(int32_t index);
16848 int32_t onBottleShopTypes()
16849 {
16850 bottleshop_list_size = 256;
16851 int32_t index = 0;
16852
16853 while(index > -1)
16854 {
16855 index = select_data("Bottle Shop Types", index, bottleshoplist, "Edit", "Done", get_zc_font(font_lfont));
16856 if(index > -1)
16857 call_bottleshop_dlg(index);
16858 }
16859
16860 return D_O_K;
16861 }
16862
16863
16864 static char item_drop_set_str_buf[70];
16865 int32_t item_drop_set_list_size=MAXITEMDROPSETS;
16866
16867 const char *itemdropsetlist(int32_t index, int32_t *list_size)
16868 {
16869 if(index>=0)
16870 {
16871 bound(index,0,item_drop_set_list_size-1);
16872 sprintf(item_drop_set_str_buf,"%3d: %s",index,item_drop_sets[index].name);
16873 return item_drop_set_str_buf;
16874 }
16875
16876 *list_size=item_drop_set_list_size;
16877 return NULL;
16878 }
16879
16880 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c);
16881
16882 static int32_t edititemdropset_1_list[] =
16883 {
16884 // dialog control number
16885 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24,25,26,27,28, -1
16886 };
16887
16888 static int32_t edititemdropset_2_list[] =
16889 {
16890 // dialog control number
16891 12, 13, 29, 30, 31, 32, 33,34,35,36,37,38,39,40,41,42,43, -1
16892 };
16893
16894 static TABPANEL edititemdropset_tabs[] =
16895 {
16896 // (text)
16897 { (char *)" Page 1 ", D_SELECTED, edititemdropset_1_list, 0, NULL },
16898 { (char *)" Page 2 ", 0, edititemdropset_2_list, 0, NULL },
16899 { NULL, 0, NULL, 0, NULL }
16900 };
16901
16902 static DIALOG edititemdropset_dlg[] =
16903 {
16904 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16905 12 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16906 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16907
16908 // 2
16909 12 { jwin_button_proc, 89, 213, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16910 12 { jwin_button_proc, 169, 213, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16911
16912 // 4
16913 12 { jwin_text_proc, 9, 29, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16914 12 { jwin_edit_proc, 39, 25, 275, 16, vc(12), vc(1), 0, 0, 32, 0, NULL, NULL, NULL },
16915 12 { jwin_text_proc, 9, 47, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Nothing Chance:", NULL, NULL },
16916 12 { d_itemdropedit_proc, 84, 43, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16917
16918 12 { jwin_tab_proc, 4, 65, 312, 143, vc(0), vc(15), 0, 0, 0, 0, (void *) edititemdropset_tabs, NULL, (void *)edititemdropset_dlg },
16919 12 { jwin_text_proc, 114, 43+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16920 // 10
16921 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16922 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16923 12 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16924 12 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16925
16926 // 14
16927 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16928 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16929 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16930 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16931 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16932 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16933 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16934 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16935 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16936 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16937 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16938 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16939 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16940 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16941 12 { jwin_text_proc, 37, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16942 // 29
16943 12 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16944 12 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16945 12 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16946 12 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16947 12 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16948 12 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16949 12 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16950 12 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16951 12 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16952 12 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16953 12 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16954 12 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16955 12 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16956 12 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16957 12 { jwin_text_proc, 39, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16958 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16959 };
16960
16961 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c)
16962 {
16963 int32_t ret = jwin_edit_proc(msg,d,c);
16964
16965 if(msg==MSG_DRAW)
16966 {
16967 int32_t t = atoi((char*)edititemdropset_dlg[7].dp);
16968
16969 for(int32_t i=0; i<10; ++i)
16970 {
16971 t += atoi((char*)edititemdropset_dlg[14+(i*3)].dp);
16972 }
16973
16974 {
16975 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[7].dp) / zc_max(t,1));
16976 sprintf((char*)edititemdropset_dlg[9].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16977 object_message(&edititemdropset_dlg[9],MSG_DRAW,c);
16978 }
16979
16980 for(int32_t i=0; i<10; ++i)
16981 {
16982 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[14+(i*3)].dp) / zc_max(t,1));
16983 sprintf((char*)edititemdropset_dlg[16+(i*3)].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16984 object_message(&edititemdropset_dlg[16+(i*3)],MSG_DRAW,c);
16985 }
16986
16987 }
16988
16989 return ret;
16990 }
16991
16992 void EditItemDropSet(int32_t index)
16993 {
16994 build_bii_list(true);
16995 char chance[11][10];
16996 char itemdropsetname[64];
16997 char caption[40];
16998 char percent_str[11][5];
16999
17000 sprintf(caption,"Item Drop Set Data %d",index);
17001 edititemdropset_dlg[0].dp = caption;
17002 edititemdropset_dlg[0].dp2=get_zc_font(font_lfont);
17003
17004 sprintf(itemdropsetname,"%s",item_drop_sets[index].name);
17005 edititemdropset_dlg[5].dp = itemdropsetname;
17006
17007 sprintf(chance[0],"%d",item_drop_sets[index].chance[0]);
17008 edititemdropset_dlg[7].dp = chance[0];
17009
17010 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
17011 sprintf(percent_str[0]," ");
17012 edititemdropset_dlg[9].dp = percent_str[0];
17013
17014 for(int32_t i=0; i<10; ++i)
17015 {
17016 sprintf(chance[i+1],"%d",item_drop_sets[index].chance[i+1]);
17017 edititemdropset_dlg[14+(i*3)].dp = chance[i+1];
17018 edititemdropset_dlg[15+(i*3)].dp = (void *) &item_list;
17019 sprintf(percent_str[i+1]," ");
17020 edititemdropset_dlg[16+(i*3)].dp = percent_str[i+1];
17021
17022 if(item_drop_sets[index].chance[i+1]==0)
17023 {
17024 edititemdropset_dlg[15+(i*3)].d1 = -2;
17025 }
17026 else
17027 {
17028 for(int32_t j=0; j<bii_cnt; j++)
17029 {
17030 if(bii[j].i == item_drop_sets[index].item[i])
17031 {
17032 edititemdropset_dlg[15+(i*3)].d1 = j;
17033 }
17034 }
17035 }
17036 }
17037
17038 large_dialog(edititemdropset_dlg);
17039
17040 int32_t ret = do_zqdialog(edititemdropset_dlg,-1);
17041
17042 if(ret==2)
17043 {
17044 saved=false;
17045
17046 sprintf(item_drop_sets[index].name,"%s",itemdropsetname);
17047
17048 item_drop_sets[index].chance[0]=atoi(chance[0]);
17049
17050 for(int32_t i=0; i<10; ++i)
17051 {
17052 item_drop_sets[index].chance[i+1]=atoi(chance[i+1]);
17053
17054 if(bii[edititemdropset_dlg[15+(i*3)].d1].i == -2)
17055 {
17056 item_drop_sets[index].chance[i+1]=0;
17057 }
17058 else
17059 {
17060 item_drop_sets[index].item[i] = bii[edititemdropset_dlg[15+(i*3)].d1].i;
17061 }
17062
17063 if(item_drop_sets[index].chance[i+1]==0)
17064 {
17065 item_drop_sets[index].item[i] = 0;
17066 }
17067 }
17068 }
17069 }
17070
17071 9 int32_t count_item_drop_sets()
17072 {
17073 9 int32_t count=0;
17074 9 bool found=false;
17075
17076
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2195 times.
2195 for(count=255; (count>0); --count)
17077 {
17078
2/2
✓ Branch 0 taken 2186 times.
✓ Branch 1 taken 24056 times.
26242 for(int32_t i=0; (i<11); ++i)
17079 {
17080
2/2
✓ Branch 0 taken 24047 times.
✓ Branch 1 taken 9 times.
24056 if(item_drop_sets[count].chance[i]!=0)
17081 {
17082 9 found=true;
17083 9 break;
17084 }
17085 24047 }
17086
17087
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2186 times.
2195 if(found)
17088 {
17089 9 break;
17090 }
17091 2186 }
17092
17093 9 return count+1;
17094 }
17095
17096 int32_t onItemDropSets()
17097 {
17098 item_drop_set_list_size = MAXITEMDROPSETS;
17099
17100 int32_t index = select_data("Item Drop Sets",0,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
17101
17102 while(index!=-1)
17103 {
17104 EditItemDropSet(index);
17105 index = select_data("Item Drop Sets",index,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
17106 }
17107
17108 return D_O_K;
17109 }
17110
17111 int32_t curr_ring = 0;
17112
17113 void EditWarpRingScr(int32_t ring,int32_t index)
17114 {
17115 char caption[40],buf[10];
17116 restore_mouse();
17117
17118 sprintf(caption,"Ring %d Warp %d",ring,index+1);
17119 warpring_warp_dlg[0].dp = (void *)caption;
17120 warpring_warp_dlg[0].dp2=get_zc_font(font_lfont);
17121
17122 sprintf(buf,"%02X",QMisc.warp[ring].scr[index]);
17123 warpring_warp_dlg[3].d1 = QMisc.warp[ring].dmap[index];
17124 warpring_warp_dlg[4].dp = buf;
17125 warpring_warp_dlg[8].dp = buf;
17126 warpring_warp_dlg[8].dp3 = &warpring_warp_dlg[3].d1;
17127
17128 vector<DIALOG*> dlgs;
17129 dlgs.push_back(&warpring_warp_dlg[3]);
17130 dlgs.push_back(&warpring_warp_dlg[4]);
17131 warpring_warp_dlg[8].dp2 = &dlgs;
17132
17133 dmap_list_size=MAXDMAPS;
17134 dmap_list_zero=true;
17135
17136 large_dialog(warpring_warp_dlg);
17137
17138 int32_t ret=do_zqdialog(warpring_warp_dlg,-1);
17139
17140 if(ret==5 || ret==6)
17141 {
17142 saved=false;
17143 QMisc.warp[ring].dmap[index] = warpring_warp_dlg[3].d1;
17144 QMisc.warp[ring].scr[index] = zc_xtoi(buf);
17145 }
17146
17147 if(ret==6)
17148 {
17149 Map.dowarp2(ring,index);
17150 refresh(rALL);
17151 }
17152 }
17153
17154 int32_t d_warplist_proc(int32_t msg,DIALOG *d,int32_t c)
17155 {
17156 if(msg==MSG_DRAW)
17157 {
17158 int32_t *xy = (int32_t*)(d->dp3);
17159 int32_t ring = curr_ring;
17160 int32_t dmap = QMisc.warp[ring].dmap[d->d1];
17161 float temp_scale = 1.5;
17162
17163 drawdmap(dmap);
17164
17165 if(xy[0]||xy[1])
17166 {
17167 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
17168 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
17169 int32_t w = 84;
17170 int32_t h = 52;
17171 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
17172 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
17173 }
17174
17175 if(xy[2]||xy[3])
17176 {
17177 textprintf_ex(screen,font,d->x+int32_t(xy[2]*temp_scale),d->y+int32_t(xy[3]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %d ",DMaps[dmap].map+1);
17178 }
17179
17180 if(xy[4]||xy[5])
17181 {
17182 textprintf_ex(screen,font,d->x+int32_t(xy[4]*temp_scale),d->y+int32_t(xy[5]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level:%2d ",DMaps[dmap].level);
17183 }
17184
17185 if(xy[6]||xy[7])
17186 {
17187 textprintf_ex(screen,font,d->x+int32_t(xy[6]*temp_scale),d->y+int32_t(xy[7]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Scr: 0x%02X ",QMisc.warp[ring].scr[d->d1]);
17188 }
17189 }
17190
17191 return jwin_list_proc(msg,d,c);
17192 }
17193
17194 int32_t d_wclist_proc(int32_t msg,DIALOG *d,int32_t c)
17195 {
17196 int32_t d1 = d->d1;
17197 int32_t ret = jwin_droplist_proc(msg,d,c);
17198 QMisc.warp[curr_ring].size=d->d1+3;
17199
17200 if(d->d1 != d1)
17201 return D_CLOSE;
17202
17203 return ret;
17204 }
17205
17206 const char *wclist(int32_t index, int32_t *list_size)
17207 {
17208 static char buf[2];
17209
17210 if(index>=0)
17211 {
17212 if(index>6)
17213 index=6;
17214
17215 sprintf(buf,"%d",index+3);
17216 return buf;
17217 }
17218
17219 *list_size=7;
17220 return NULL;
17221 }
17222
17223 //int32_t warpringdmapxy[8] = {160,116,160,90,160,102,160,154};
17224 int32_t warpringdmapxy[8] = {80,26,80,0,80,12,80,78};
17225
17226 12 static ListData number_list(numberlist, &font);
17227 12 static ListData wc_list(wclist, &font);
17228
17229 static DIALOG warpring_dlg[] =
17230 {
17231 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
17232 12 { jwin_win_proc, 0, 0, 193, 166, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
17233 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17234 12 { jwin_text_proc, 16, 33, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Count:", NULL, NULL },
17235 12 { d_wclist_proc, 72, 29, 48, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &wc_list, NULL, NULL },
17236 // 4
17237 12 { d_warplist_proc, 16, 50, 65, 71, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &number_list, NULL, warpringdmapxy },
17238 12 { jwin_button_proc, 26, 140, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
17239 12 { jwin_button_proc, 106, 140, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
17240 12 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
17241 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17242 };
17243
17244 int32_t select_warp()
17245 {
17246 QMisc.warp[curr_ring].size = vbound(QMisc.warp[curr_ring].size,3,9);
17247 number_list_zero = false;
17248
17249 int32_t ret=4;
17250
17251 large_dialog(warpring_dlg);
17252
17253 do
17254 {
17255 number_list_size = QMisc.warp[curr_ring].size;
17256 warpring_dlg[3].d1 = QMisc.warp[curr_ring].size-3;
17257 ret = do_zqdialog(warpring_dlg,ret);
17258 }
17259 while(ret==3);
17260
17261 if(ret==6 || ret==0)
17262 {
17263 return -1;
17264 }
17265
17266 return warpring_dlg[4].d1;
17267 }
17268
17269 void EditWarpRing(int32_t ring)
17270 {
17271 char buf[40];
17272 sprintf(buf,"Ring %d Warps",ring);
17273 warpring_dlg[0].dp = buf;
17274 warpring_dlg[0].dp2 = get_zc_font(font_lfont);
17275 curr_ring = ring;
17276
17277 int32_t index = select_warp();
17278
17279 while(index!=-1)
17280 {
17281 EditWarpRingScr(ring,index);
17282 index = select_warp();
17283 }
17284 }
17285
17286 int32_t onWarpRings()
17287 {
17288 number_list_size = 9;
17289 number_list_zero = true;
17290
17291 int32_t index = select_data("Warp Rings",0,numberlist,"Edit","Done",get_zc_font(font_lfont));
17292
17293 while(index!=-1)
17294 {
17295 EditWarpRing(index);
17296 number_list_size = 9;
17297 number_list_zero = true;
17298 index = select_data("Warp Rings",index,numberlist,"Edit","Done",get_zc_font(font_lfont));
17299 }
17300
17301 return D_O_K;
17302 }
17303
17304 const char *enemy_viewer(int32_t index, int32_t *list_size)
17305 {
17306 if(index<0)
17307 {
17308 *list_size=10;
17309
17310 return NULL;
17311 }
17312
17313 int32_t guy=Map.CurrScr()->enemy[index];
17314
17315 if (guy == 0) return "(None)";
17316 return guy>=eSTART ? guy_string[guy] : (char *) "(Guy - Do Not Use!)";
17317 }
17318
17319 enemy_struct bie[eMAXGUYS];
17320 enemy_struct ce[100];
17321 int32_t enemy_type=0,bie_cnt=-1,ce_cnt;
17322
17323 enemy_struct big[zqMAXGUYS];
17324 enemy_struct cg[100];
17325 int32_t guy_type=0,big_cnt=-1,cg_cnt;
17326
17327 //Uses old_max_guys[] in zq_misc.cpp to define what are visible if bool hide is set true. -Z
17328 void build_bie_list(bool hide)
17329 {
17330 bie[0].s = (char *)"(None)";
17331 bie[0].i = 0;
17332 bie_cnt=1;
17333
17334 for(int32_t i=1; i<eMAXGUYS; i++)
17335 {
17336 if (i < eSTART) continue; // ignore guys - enemies only!
17337
17338 if(i >= OLDMAXGUYS || old_guy_string[i][strlen(old_guy_string[i])-1]!=' ' || !hide)
17339 {
17340 bie[bie_cnt].s = (char *)guy_string[i];
17341 bie[bie_cnt].i = i;
17342 ++bie_cnt;
17343 }
17344 }
17345
17346 for(int32_t i=1; i<bie_cnt-1; i++) //Start at 1 so '(None)' isn't alphabetized!
17347 {
17348 for(int32_t j=i+1; j<bie_cnt; j++)
17349 {
17350 if(strcmp(bie[i].s,bie[j].s)>0)
17351 {
17352 zc_swap(bie[i],bie[j]);
17353 }
17354 }
17355 }
17356 }
17357
17358 int32_t efrontfacingtile(int32_t id)
17359 {
17360 int32_t anim = get_qr(qr_NEWENEMYTILES)?guysbuf[id].e_anim:guysbuf[id].anim;
17361 int32_t usetile = 0;
17362
17363 switch(anim)
17364 {
17365
17366 case aNONE: break;
17367 case aAQUA:
17368 if(!(get_qr(qr_NEWENEMYTILES) && guysbuf[id].attributes[0]))
17369 break;
17370
17371 case aWALLM:
17372 case aGHOMA:
17373 usetile=1;
17374 break;
17375
17376 //Fallthrough
17377 case a2FRM4DIR:
17378 case aWALK:
17379 usetile=2;
17380 break;
17381
17382 case aLEV:
17383 case a3FRM4DIR:
17384 usetile=3;
17385 break;
17386
17387 case aLANM:
17388 usetile = !(get_qr(qr_NEWENEMYTILES))?0:4;
17389 break;
17390
17391 case aNEWDONGO:
17392 case a4FRM8EYE:
17393 case aNEWWIZZ:
17394 case aARMOS4:
17395 case aNEWTEK:
17396 case aNEWWALLM:
17397 case a4FRM4DIRF:
17398 case a4FRM4DIR:
17399 case a4FRM8DIRF:
17400 case a4FRMPOS8DIR:
17401 case a4FRMPOS8DIRF:
17402 case a4FRMPOS4DIR:
17403 case a4FRMPOS4DIRF:
17404 usetile=4;
17405 break;
17406
17407 case aDONGO:
17408 usetile=6;
17409 break;
17410
17411 case aDONGOBS:
17412 usetile=24;
17413 break;
17414
17415 case aNEWLEV:
17416 usetile=40;
17417 break;
17418
17419 case aNEWZORA:
17420 if(guysbuf[id].family==eeZORA)
17421 usetile=44;
17422
17423 break;
17424
17425 case aGLEEOK:
17426 if(!get_qr(qr_NEWENEMYTILES))
17427 usetile = (guysbuf[id].s_tile - guysbuf[id].tile)+1;
17428 else
17429 usetile = (guysbuf[id].attributes[7]);
17430
17431 break;
17432 }
17433
17434 return zc_max(get_qr(qr_NEWENEMYTILES) ? -guysbuf[id].e_tile
17435 : -guysbuf[id].tile, usetile);
17436 }
17437
17438 int32_t onEnemies()
17439 {
17440 call_screenenemies_dialog();
17441 refresh(rALL);
17442 return D_O_K;
17443 }
17444
17445 char author[65],title[65],password[32];
17446
17447 int32_t d_showedit_proc(int32_t msg,DIALOG *d,int32_t c)
17448 {
17449 int32_t ret = jwin_edit_proc(msg,d,c);
17450
17451 if(msg==MSG_DRAW)
17452 {
17453 (d+1)->proc(MSG_DRAW,d+1,0);
17454 }
17455
17456 return ret;
17457 }
17458
17459 int32_t onHeader()
17460 {
17461 call_header_dlg();
17462 return D_O_K;
17463 }
17464
17465 void call_cheats_dlg();
17466 int32_t onCheats()
17467 {
17468 call_cheats_dlg();
17469 return D_O_K;
17470 }
17471
17472 bool do_x_button(BITMAP *dest, int32_t x, int32_t y)
17473 {
17474 bool over=false;
17475
17476 while(gui_mouse_b())
17477 {
17478 custom_vsync();
17479
17480 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17481 {
17482 if(!over)
17483 {
17484 draw_x_button(dest, x, y, D_SELECTED);
17485 over=true;
17486 }
17487 }
17488 else
17489 {
17490 if(over)
17491 {
17492 draw_x_button(dest, x, y, 0);
17493 over=false;
17494 }
17495 }
17496 }
17497
17498 return over;
17499 }
17500
17501 bool do_question_button(BITMAP *dest, int32_t x, int32_t y)
17502 {
17503 bool over=false;
17504
17505 while(gui_mouse_b())
17506 {
17507 custom_vsync();
17508
17509 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17510 {
17511 if(!over)
17512 {
17513 draw_question_button(dest, x, y, D_SELECTED);
17514 over=true;
17515 }
17516 }
17517 else
17518 {
17519 if(over)
17520 {
17521 draw_question_button(dest, x, y, 0);
17522 over=false;
17523 }
17524 }
17525 }
17526
17527 return over;
17528 }
17529
17530
17531 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
17532 {
17533 return D_O_K;
17534 }
17535
17536 int32_t d_maptile_proc(int32_t msg, DIALOG *d, int32_t)
17537 {
17538 switch(msg)
17539 {
17540 case MSG_CLICK:
17541 if(select_tile(d->d1,d->d2,1,d->fg,true, 0, true))
17542 return D_REDRAW;
17543
17544 case MSG_DRAW:
17545 {
17546 int32_t dw = d->w;
17547 int32_t dh = d->h;
17548
17549 if(d->dp2==(void*)1)
17550 {
17551 dw /= 2;
17552 dh /= 2;
17553 }
17554
17555 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17556
17557 if(buf)
17558 {
17559 clear_bitmap(buf);
17560
17561 for(int32_t y=0; y<dh; y+=16)
17562 for(int32_t x=0; x<dw; x+=16)
17563 {
17564 if(d->d1)
17565 puttile16(buf,d->d1+(y>>4)*20+(x>>4),x,y,d->fg,0);
17566 }
17567
17568 if(d->dp2==(void*)1)
17569 stretch_blit(buf,screen,0,0,dw,dh,d->x-1,d->y-1,dw*2,dh*2);
17570 else
17571 blit(buf,screen,0,0,d->x,d->y,dw,dh);
17572
17573 destroy_bitmap(buf);
17574 }
17575 }
17576 }
17577
17578 return D_O_K;
17579 }
17580
17581 static int32_t last_combo=0;
17582 static int32_t last_cset=0;
17583
3/4
✓ Branch 0 taken 98304 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98292 times.
✓ Branch 3 taken 12 times.
98304 static combo_alias temp_aliases[MAXCOMBOALIASES];
17584
17585 static char comboa_str_buf[32];
17586
17587 int32_t d_comboalist_proc(int32_t msg,DIALOG *d,int32_t c)
17588 {
17589 int32_t d1 = d->d1;
17590 int32_t ret = jwin_droplist_proc(msg,d,c);
17591 comboa_cnt = d->d1;
17592
17593 if(d1!=d->d1)
17594 {
17595 set_comboaradio(temp_aliases[comboa_cnt].layermask);
17596 return D_REDRAW;
17597 }
17598
17599 return ret;
17600 }
17601
17602 const char *comboalist(int32_t index, int32_t *list_size)
17603 {
17604 if(index>=0)
17605 {
17606 bound(index,0,MAXCOMBOALIASES-1);
17607 sprintf(comboa_str_buf,"%d",index);
17608 return comboa_str_buf;
17609 }
17610
17611 *list_size=MAXCOMBOALIASES;
17612 return NULL;
17613 }
17614
17615 extern int32_t scheme[jcMAX];
17616
17617 int32_t d_comboa_proc(int32_t msg,DIALOG *d,int32_t c)
17618 {
17619 //these are here to bypass compiler warnings about unused arguments
17620 c=c;
17621
17622 combo_alias *combo;
17623 combo = &temp_aliases[comboa_cnt];
17624 int32_t position;
17625 int32_t cur_layer, temp_layer;
17626 int32_t lay_count=0;
17627 int32_t size = 2;
17628
17629 int32_t cx1=(gui_mouse_x()-d->x-(120-(combo->width*8)));
17630 int32_t cy1=(gui_mouse_y()-d->y-(80-(combo->height*8)));
17631 int32_t cx=cx1/(16*size);
17632 int32_t cy=cy1/(16*size);
17633
17634 int32_t co,cs;
17635
17636
17637 switch(msg)
17638 {
17639 case MSG_CLICK:
17640 if((cx>combo->width)||(cx1<0))
17641 return D_O_K;
17642
17643 if((cy>combo->height)||(cy1<0))
17644 return D_O_K;
17645
17646 for(int32_t j=0; j<layer_cnt; j++)
17647 {
17648 if(combo->layermask&(1<<j))
17649 lay_count++;
17650 }
17651
17652 position=(lay_count)*(combo->width+1)*(combo->height+1);
17653 position+=(cy*(combo->width+1))+cx;
17654
17655 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
17656 {
17657 combo->combos[position] = 0;
17658 combo->csets[position] = 0;
17659
17660 while(gui_mouse_b())
17661 {
17662 /* do nothing */
17663 rest(1);
17664 }
17665
17666 return D_REDRAW;
17667 }
17668
17669 co=combo->combos[position];
17670 cs=combo->csets[position];
17671
17672 if((co==0)||(key[KEY_ZC_LCONTROL]))
17673 {
17674 co=last_combo;
17675 cs=last_cset;
17676 }
17677
17678 if((select_combo_2(co,cs)))
17679 {
17680 last_combo = co;
17681 last_cset = cs;
17682
17683 combo->combos[position]=co;
17684 combo->csets[position]=cs;
17685 }
17686
17687 return D_REDRAW;
17688 break;
17689
17690 case MSG_DRAW:
17691 BITMAP *buf = create_bitmap_ex(8,d->w,d->h);
17692
17693 if(buf)
17694 {
17695 clear_bitmap(buf);
17696
17697 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17698 {
17699 int32_t k=0;
17700 cur_layer=0;
17701 temp_layer=combo->layermask;
17702
17703 while((temp_layer!=0)&&(k<z))
17704 {
17705 if(temp_layer&1)
17706 {
17707 k++;
17708 }
17709
17710 cur_layer++;
17711 temp_layer = temp_layer>>1;
17712 }
17713
17714 for(int32_t y=0; (y<d->h)&&((y/16)<=combo->height); y+=16)
17715 {
17716 for(int32_t x=0; (x<d->w)&&((x/16)<=combo->width); x+=16)
17717 {
17718 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y/16)*(combo->width+1))+(x/16));
17719
17720 if(combo->combos[cpos])
17721 {
17722 if(!((d-1)->flags&D_SELECTED)||(cur_layer==layer_cnt))
17723 {
17724 if(z==0)
17725 {
17726 puttile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17727 }
17728 else
17729 {
17730 overtile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17731 }
17732 }
17733 }
17734 }
17735 }
17736 }
17737
17738 rectfill(screen, d->x-2,d->y-2,d->x+256+2,d->y+176+2,jwin_pal[jcBOX]);
17739 int32_t dx = 120-(combo->width*8)+d->x;
17740 int32_t dy = 80-(combo->height*8)+d->y;
17741 stretch_blit(buf,screen,0,0,(combo->width+1)*16,(combo->height+1)*16,dx,dy,(combo->width+1)*16*size,(combo->height+1)*16*size);
17742 //blit(buf,screen,0,0,120-(combo->width*8)+d->x,80-(combo->height*8)+d->y,(combo->width+1)*16,(combo->height+1)*16);
17743 (d-11)->w = (combo->width+1)*16*size+2;
17744 (d-11)->h = (combo->height+1)*16*size+2;
17745 (d-11)->x = 120-(combo->width*8)+4*size+2+(d-14)->x;
17746 (d-11)->y = 80-(combo->height*8)+25*size+2+(d-14)->y;
17747 object_message((d-11),MSG_DRAW,0);
17748
17749 destroy_bitmap(buf);
17750 }
17751
17752 break;
17753 }
17754
17755 return D_O_K;
17756 }
17757
17758 void draw_combo_alias_thumbnail(BITMAP *dest, combo_alias const* combo, int32_t x, int32_t y, int32_t size)
17759 {
17760 if(!combo->combo)
17761 {
17762 int32_t cur_layer, temp_layer;
17763
17764 int32_t cw=combo->width+1;
17765 int32_t ch=combo->height+1;
17766 int32_t dw=cw<<4;
17767 int32_t dh=ch<<4;
17768 int32_t sw=16, sh=16, sx=0, sy=0;
17769
17770 if(cw<ch)
17771 {
17772 sw=((cw<<4)/ch);
17773 sx=((16-sw)>>1);
17774 }
17775 else
17776 {
17777 sh=((ch<<4)/cw);
17778 sy=((16-sh)>>1);
17779 }
17780
17781 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17782 BITMAP *buf2 = create_bitmap_ex(8, 16*size, 16*size);
17783 clear_bitmap(buf);
17784 clear_bitmap(buf2);
17785
17786 if(buf&&(combo->width>0||combo->height>0||combo->combos[0]>0))
17787 {
17788 clear_bitmap(buf);
17789
17790 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17791 {
17792 int32_t k=0;
17793 cur_layer=0;
17794 temp_layer=combo->layermask;
17795
17796 while((temp_layer!=0)&&(k<z))
17797 {
17798 if(temp_layer&1)
17799 {
17800 k++;
17801 }
17802
17803 cur_layer++;
17804 temp_layer = temp_layer>>1;
17805 }
17806
17807 for(int32_t y2=0; (y2<dh)&&((y2>>4)<=combo->height); y2+=16)
17808 {
17809 for(int32_t x2=0; (x2<dw)&&((x2>>4)<=combo->width); x2+=16)
17810 {
17811 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y2/16)*(combo->width+1))+(x2/16));
17812
17813 if(combo->combos[cpos])
17814 {
17815 if(z==0)
17816 {
17817 puttile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17818 }
17819 else
17820 {
17821 overtile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17822 }
17823 }
17824 }
17825 }
17826 }
17827
17828 stretch_blit(buf, buf2, 0, 0, (cw*16), (ch*16), sx*size, sy*size, sw*size, sh*size);
17829 blit(buf2, dest, 0, 0, x, y, 16*size, 16*size);
17830 }
17831 else
17832 {
17833 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17834 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17835 }
17836
17837 if(buf)
17838 destroy_bitmap(buf);
17839
17840 if(buf2)
17841 destroy_bitmap(buf2);
17842 }
17843 else
17844 {
17845 if(combobuf[combo->combo].tile>0)
17846 {
17847 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17848 put_combo(dest, x, y, combo->combo, combo->cset, 0, 0, size);
17849 }
17850 else
17851 {
17852 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17853 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17854 }
17855 }
17856 }
17857
17858 int32_t d_comboat_proc(int32_t msg,DIALOG *d,int32_t)
17859 {
17860 switch(msg)
17861 {
17862 case MSG_CLICK:
17863 {
17864 int32_t c2;
17865 int32_t cs;
17866 c2=temp_aliases[comboa_cnt].combo;
17867 cs=temp_aliases[comboa_cnt].cset;
17868
17869 if(gui_mouse_b()&2) //right mouse button
17870 {
17871 if(c2==0&&cs==0&&!(gui_mouse_b()&1))
17872 {
17873 return D_O_K;
17874 }
17875
17876 temp_aliases[comboa_cnt].combo=0;
17877 temp_aliases[comboa_cnt].cset=0;
17878 }
17879
17880 if(gui_mouse_b()&1) //left mouse button
17881 {
17882 if(select_combo_2(c2, cs))
17883 {
17884 temp_aliases[comboa_cnt].combo=c2;
17885 temp_aliases[comboa_cnt].cset=cs;
17886 }
17887
17888 return D_REDRAW;
17889 }
17890 else
17891 {
17892 return D_REDRAWME;
17893 }
17894 }
17895 break;
17896
17897 case MSG_DRAW:
17898 draw_combo_alias_thumbnail(screen, &temp_aliases[comboa_cnt], d->x-1, d->y-1,2);
17899 break;
17900
17901 default:
17902 break;
17903 }
17904
17905 return D_O_K;
17906 }
17907
17908 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c);
17909
17910 static DIALOG orgcomboa_dlg[] =
17911 {
17912 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17913 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Organize Combo Aliases", NULL, NULL },
17914 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17915 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17916
17917 { jwin_radio_proc, 10, 40, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Copy", NULL, NULL },
17918 { jwin_text_proc, 10, 50, 33, 9, 0, 0, 0, 0, 0, 0, (void *) "", NULL, NULL },
17919 // { jwin_radio_proc, 10, 50, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Move", NULL, NULL },
17920 { jwin_radio_proc, 10, 60, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Swap", NULL, NULL },
17921 /* 6 */ { jwin_edit_proc, 110, 35, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17922 { jwin_edit_proc, 110, 55, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17923 { jwin_text_proc, 60, 40, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Source", NULL, NULL },
17924 { jwin_text_proc, 60, 60, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Dest", NULL, NULL},
17925 { jwin_radio_proc, 10, 80, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Insert new (before source)", NULL, NULL },
17926 { jwin_radio_proc, 10, 100, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Delete source", NULL, NULL },
17927 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17928 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17929 };
17930
17931 static DIALOG newcomboa_dlg[] =
17932 {
17933 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17934 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Properties", NULL, NULL },
17935 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17936 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17937 { jwin_text_proc, 24, 34, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Width", NULL, NULL },
17938 { jwin_text_proc, 24, 52, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Height", NULL, NULL },
17939 { jwin_text_proc, 24, 70, 100, 8, 0, 0, 0, 0, 0, 0, (void *) "Layers to Draw On:", NULL, NULL },
17940 { jwin_edit_proc, 104, 30, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17941 { jwin_edit_proc, 122, 48, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17942 { jwin_check_proc, 24, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "1", NULL, NULL },
17943 { jwin_check_proc, 50, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "2", NULL, NULL },
17944 { jwin_check_proc, 76, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "3", NULL, NULL },
17945 { jwin_check_proc, 102, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "4", NULL, NULL },
17946 { jwin_check_proc, 128, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "5", NULL, NULL },
17947 { jwin_check_proc, 154, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "6", NULL, NULL },
17948
17949
17950 // { jwin_text_proc, 24, 106, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Copy to :", NULL, NULL },
17951 //15
17952 // { jwin_edit_proc, 100, 100, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17953 // { jwin_check_proc, 84, 106, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "", NULL, NULL },
17954
17955 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17956 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17957 };
17958
17959 bool swapComboAlias(int32_t source, int32_t dest)
17960 {
17961 if(source==dest)
17962 return false;
17963 zc_swap(temp_aliases[source],temp_aliases[dest]);
17964 return true;
17965 }
17966
17967
17968 bool copyComboAlias(int32_t source, int32_t dest)
17969 {
17970 if(source == dest)
17971 return false;
17972 temp_aliases[dest] = temp_aliases[source];
17973 return true;
17974 }
17975
17976 int32_t getcurrentcomboalias();
17977
17978 int32_t onOrgComboAliases()
17979 {
17980 char cSrc[8];
17981 char cDest[8];
17982 sprintf(cSrc,"%d", getcurrentcomboalias());
17983 strcpy(cDest,cSrc);
17984 int32_t iSrc = 0;
17985 int32_t iDest = 0;
17986
17987 //sprintf(cSrc,"0");
17988 //sprintf(cDest,"0");
17989 orgcomboa_dlg[0].dp2=get_zc_font(font_lfont);
17990 orgcomboa_dlg[6].dp= cSrc;
17991 orgcomboa_dlg[7].dp= cDest;
17992 int32_t ret = 1;
17993 large_dialog(orgcomboa_dlg);
17994 do
17995 {
17996 iSrc = atoi((char*)orgcomboa_dlg[6].dp);
17997 iDest = atoi((char*)orgcomboa_dlg[7].dp);
17998 ret = do_zqdialog(orgcomboa_dlg,-1);
17999
18000 if(ret!=1) return ret;
18001
18002 if((atoi((char*) orgcomboa_dlg[6].dp))<0 || (atoi((char*) orgcomboa_dlg[6].dp)) > MAXCOMBOALIASES-1)
18003 {
18004 char buf[100];
18005 snprintf(buf, 100, "Invalid source (range 0-%d)", MAXCOMBOALIASES-1);
18006 buf[99]='\0';
18007 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
18008 ret = 1;
18009 }
18010
18011 // 10,11=ins, del
18012 if(orgcomboa_dlg[10].flags & D_SELECTED) //insert
18013 {
18014 for(int32_t j=MAXCOMBOALIASES-1; j>(atoi((char*) orgcomboa_dlg[6].dp)); --j)
18015 copyComboAlias(j-1,j);
18016 ret = -1;
18017 }
18018
18019 if(orgcomboa_dlg[11].flags & D_SELECTED) //delete
18020 {
18021 for(int32_t j=(atoi((char*) orgcomboa_dlg[6].dp)); j<MAXCOMBOALIASES-1; ++j)
18022 copyComboAlias(j+1,j);
18023 ret = -1;
18024 }
18025
18026 if((atoi((char*) orgcomboa_dlg[6].dp)) == (atoi((char*) orgcomboa_dlg[7].dp)))
18027 {
18028 jwin_alert("Error","Source and dest can't be the same.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
18029 ret = 1;
18030 }
18031
18032 if((atoi((char*) orgcomboa_dlg[7].dp)) < 0 || (atoi((char*) orgcomboa_dlg[7].dp)) > MAXCOMBOALIASES-1)
18033 {
18034 char buf[100];
18035 snprintf(buf, 100, "Invalid dest (range 0-%d)", MAXCOMBOALIASES-1);
18036 buf[99]='\0';
18037
18038 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
18039 ret = 1;
18040 }
18041
18042 if(orgcomboa_dlg[3].flags & D_SELECTED) //copy
18043 {
18044 copyComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
18045 ret = -1;
18046 }
18047
18048 if(orgcomboa_dlg[5].flags & D_SELECTED) //swap
18049 {
18050 swapComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
18051 ret = -1;
18052 }
18053 }
18054 while(ret==1);
18055 return ret;
18056 }
18057
18058 int32_t onNewComboAlias()
18059 {
18060 combo_alias *combo;
18061 combo = &temp_aliases[comboa_cnt];
18062
18063 char cwidth[5];
18064 char cheight[5];
18065 // char cp[3];
18066
18067 word temp_combos[16*11*7];
18068 byte temp_csets[16*11*7];
18069 sprintf(cwidth, "%d", combo->width+1);
18070 sprintf(cheight, "%d", combo->height+1);
18071 int32_t old_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
18072 int32_t old_width=combo->width;
18073 int32_t old_height=combo->height;
18074 int32_t oldlayer=combo->layermask;
18075
18076 for(int32_t i=0; i<old_count; i++)
18077 {
18078 temp_csets[i] = combo->csets[i];
18079 temp_combos[i] = combo->combos[i];
18080 }
18081
18082 newcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18083 newcomboa_dlg[6].dp = cwidth;
18084 newcomboa_dlg[7].dp = cheight;
18085 newcomboa_dlg[8].flags = (combo->layermask&1)? D_SELECTED : 0;
18086 newcomboa_dlg[9].flags = (combo->layermask&2)? D_SELECTED : 0;
18087 newcomboa_dlg[10].flags = (combo->layermask&4)? D_SELECTED : 0;
18088 newcomboa_dlg[11].flags = (combo->layermask&8)? D_SELECTED : 0;
18089 newcomboa_dlg[12].flags = (combo->layermask&16)? D_SELECTED : 0;
18090 newcomboa_dlg[13].flags = (combo->layermask&32)? D_SELECTED : 0;
18091
18092 large_dialog(newcomboa_dlg);
18093
18094 int32_t ret = do_zqdialog(newcomboa_dlg,-1);
18095
18096 if(ret==1)
18097 {
18098 combo->width = ((atoi(cwidth)-1)<16)?zc_max(0,(atoi(cwidth)-1)):15;
18099 combo->height = ((atoi(cheight)-1)<11)?zc_max(0,(atoi(cheight)-1)):10;
18100 combo->layermask=0;
18101 combo->layermask |= (newcomboa_dlg[8].flags&D_SELECTED)?1:0;
18102 combo->layermask |= (newcomboa_dlg[9].flags&D_SELECTED)?2:0;
18103 combo->layermask |= (newcomboa_dlg[10].flags&D_SELECTED)?4:0;
18104 combo->layermask |= (newcomboa_dlg[11].flags&D_SELECTED)?8:0;
18105 combo->layermask |= (newcomboa_dlg[12].flags&D_SELECTED)?16:0;
18106 combo->layermask |= (newcomboa_dlg[13].flags&D_SELECTED)?32:0;
18107
18108 int32_t new_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
18109
18110 combo->combos.clear();
18111 combo->csets.clear();
18112
18113 int32_t j=1;
18114 int32_t old_size=(old_width+1)*(old_height+1);
18115 int32_t new_start[7] =
18116 {
18117 0,
18118 ((combo->width+1)*(combo->height+1)*(1)),
18119 ((combo->width+1)*(combo->height+1)*(2)),
18120 ((combo->width+1)*(combo->height+1)*(3)),
18121 ((combo->width+1)*(combo->height+1)*(4)),
18122 ((combo->width+1)*(combo->height+1)*(5)),
18123 ((combo->width+1)*(combo->height+1)*(6))
18124 };
18125 int32_t new_layers[6] = {0,0,0,0,0,0};
18126 int32_t temp_layer = combo->layermask;
18127 int32_t temp_old = oldlayer;
18128 int32_t old_layers[6] = {0,0,0,0,0,0};
18129 int32_t k=1;
18130
18131 for(int32_t i=0; (i<6)&&(temp_layer!=0); j++,temp_layer>>=1,temp_old>>=1)
18132 {
18133 if(temp_layer&1)
18134 {
18135 new_layers[i] = j;
18136 //if(oldlayer&(1<<(j-1))) old_layers[i] = k++;
18137 i++;
18138 }
18139
18140 if(temp_old&1)
18141 {
18142 if(temp_layer&1)
18143 {
18144 old_layers[i-1] = k;
18145 }
18146
18147 k++;
18148 }
18149 }
18150
18151 for(int32_t i=0; i<new_count; i++)
18152 {
18153 if(i>=new_start[6])
18154 {
18155 //oldl=oldlayer>>(new_layers[5]-1);
18156 j=i-new_start[6];
18157
18158 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[5]-1))))
18159 {
18160 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18161 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18162 }
18163 else
18164 {
18165 combo->combos[i] = 0;
18166 combo->csets[i] = 0;
18167 }
18168 }
18169 else if(i>=new_start[5])
18170 {
18171 //oldl=oldlayer>>(new_layers[4]-1);
18172 j=i-new_start[5];
18173
18174 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[4]-1))))
18175 {
18176 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18177 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18178 }
18179 else
18180 {
18181 combo->combos[i] = 0;
18182 combo->csets[i] = 0;
18183 }
18184 }
18185 else if(i>=new_start[4])
18186 {
18187 //oldl=oldlayer>>(new_layers[3]-1);
18188 j=i-new_start[4];
18189
18190 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[3]-1))))
18191 {
18192 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18193 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18194 }
18195 else
18196 {
18197 combo->combos[i] = 0;
18198 combo->csets[i] = 0;
18199 }
18200 }
18201 else if(i>=new_start[3])
18202 {
18203 //oldl=oldlayer>>(new_layers[2]-1);
18204 j=i-new_start[3];
18205
18206 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[2]-1))))
18207 {
18208 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18209 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18210 }
18211 else
18212 {
18213 combo->combos[i] = 0;
18214 combo->csets[i] = 0;
18215 }
18216 }
18217 else if(i>=new_start[2])
18218 {
18219 //oldl=oldlayer>>(new_layers[1]-1);
18220 j=i-new_start[2];
18221
18222 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[1]-1))))
18223 {
18224 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18225 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18226 }
18227 else
18228 {
18229 combo->combos[i] = 0;
18230 combo->csets[i] = 0;
18231 }
18232 }
18233 else if(i>=new_start[1])
18234 {
18235 //oldl=oldlayer>>(new_layers[0]-1);
18236 j=i-new_start[1];
18237
18238 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[0]-1))))
18239 {
18240 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18241 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18242 }
18243 else
18244 {
18245 combo->combos[i] = 0;
18246 combo->csets[i] = 0;
18247 }
18248 }
18249 else if(i>=new_start[0])
18250 {
18251 if(((i/(combo->width+1))<=old_height)&&((i%(combo->width+1))<=old_width))
18252 {
18253 combo->combos[i] = temp_combos[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18254 combo->csets[i] = temp_csets[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18255 }
18256 else
18257 {
18258 combo->combos[i] = 0;
18259 combo->csets[i] = 0;
18260 }
18261 }
18262 }
18263
18264 set_comboaradio(combo->layermask);
18265 }
18266
18267 return ret;
18268 }
18269
18270 int32_t d_orgcomboa_proc(int32_t msg, DIALOG *d, int32_t c)
18271 {
18272 //these are here to bypass compiler warnings about unused arguments
18273 c=c;
18274
18275 int32_t down=0;
18276 int32_t selected=(d->flags&D_SELECTED)?1:0;
18277 int32_t last_draw;
18278
18279 switch(msg)
18280 {
18281
18282 case MSG_DRAW:
18283 {
18284 FONT *tfont=font;
18285 font=get_zc_font(font_lfont_l);
18286 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18287 font=tfont;
18288 }
18289 break;
18290
18291 case MSG_WANTFOCUS:
18292 return D_WANTFOCUS;
18293
18294 case MSG_KEY:
18295 /* close dialog? */
18296 onOrgComboAliases();
18297 return D_REDRAW;
18298
18299 /* or just toggle */
18300 /*d->flags ^= D_SELECTED;
18301 object_message(d, MSG_DRAW, 0);
18302 break;*/
18303
18304 case MSG_CLICK:
18305 last_draw = 0;
18306
18307 /* track the mouse until it is released */
18308 while(gui_mouse_b())
18309 {
18310 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18311
18312 /* redraw? */
18313 if(last_draw != down)
18314 {
18315 if(down != selected)
18316 d->flags |= D_SELECTED;
18317 else
18318 d->flags &= ~D_SELECTED;
18319
18320 object_message(d, MSG_DRAW, 0);
18321 last_draw = down;
18322 }
18323
18324 /* let other objects continue to animate */
18325 broadcast_dialog_message(MSG_IDLE, 0);
18326 }
18327
18328 /* redraw in normal state */
18329 if(down)
18330 {
18331 if(d->flags&D_EXIT)
18332 {
18333 d->flags &= ~D_SELECTED;
18334 object_message(d, MSG_DRAW, 0);
18335 }
18336 }
18337
18338 /* should we close the dialog? */
18339 if(down)
18340 {
18341 onOrgComboAliases();
18342 return D_REDRAW;
18343 }
18344
18345 break;
18346 }
18347
18348 return D_O_K;
18349 }
18350
18351 int32_t d_comboabutton_proc(int32_t msg, DIALOG *d, int32_t c)
18352 {
18353 //these are here to bypass compiler warnings about unused arguments
18354 c=c;
18355
18356 int32_t down=0;
18357 int32_t selected=(d->flags&D_SELECTED)?1:0;
18358 int32_t last_draw;
18359
18360 switch(msg)
18361 {
18362
18363 case MSG_DRAW:
18364 {
18365 FONT *tfont=font;
18366 font=get_zc_font(font_lfont_l);
18367 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18368 font=tfont;
18369 }
18370 break;
18371
18372 case MSG_WANTFOCUS:
18373 return D_WANTFOCUS;
18374
18375 case MSG_KEY:
18376 /* close dialog? */
18377 onNewComboAlias();
18378 return D_REDRAW;
18379
18380 /* or just toggle */
18381 /*d->flags ^= D_SELECTED;
18382 object_message(d, MSG_DRAW, 0);
18383 break;*/
18384
18385 case MSG_CLICK:
18386 last_draw = 0;
18387
18388 /* track the mouse until it is released */
18389 while(gui_mouse_b())
18390 {
18391 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18392
18393 /* redraw? */
18394 if(last_draw != down)
18395 {
18396 if(down != selected)
18397 d->flags |= D_SELECTED;
18398 else
18399 d->flags &= ~D_SELECTED;
18400
18401 object_message(d, MSG_DRAW, 0);
18402 last_draw = down;
18403 }
18404
18405 /* let other objects continue to animate */
18406 broadcast_dialog_message(MSG_IDLE, 0);
18407 }
18408
18409 /* redraw in normal state */
18410 if(down)
18411 {
18412 if(d->flags&D_EXIT)
18413 {
18414 d->flags &= ~D_SELECTED;
18415 object_message(d, MSG_DRAW, 0);
18416 }
18417 }
18418
18419 /* should we close the dialog? */
18420 if(down)
18421 {
18422 onNewComboAlias();
18423 return D_REDRAW;
18424 }
18425
18426 break;
18427 }
18428
18429 return D_O_K;
18430 }
18431
18432 int32_t d_comboacheck_proc(int32_t msg, DIALOG *d, int32_t c)
18433 {
18434 int32_t temp = d->flags&D_SELECTED;
18435 int32_t ret=jwin_checkfont_proc(msg,d,c);
18436
18437 if(temp != (d->flags&D_SELECTED))
18438 {
18439 return D_REDRAW;
18440 }
18441
18442 return ret;
18443 }
18444
18445 12 static ListData comboa_list(comboalist, &font);
18446
18447 static DIALOG editcomboa_dlg[] =
18448 {
18449 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
18450 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Edit", NULL, NULL },
18451 { jwin_button_proc, 148, 212, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
18452 { jwin_button_proc, 232, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18453 { jwin_frame_proc, 4+121, 28+81, 1, 1, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18454 { d_comboabutton_proc, 25, 212, 81, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Properties", NULL, NULL },
18455 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18456 { d_comboa_radio_proc, 285, 44, 30, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "0", NULL, NULL },
18457 { d_comboa_radio_proc, 285, 54, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
18458 { d_comboa_radio_proc, 285, 64, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
18459 { d_comboa_radio_proc, 285, 74, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
18460 { d_comboa_radio_proc, 285, 84, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
18461
18462 { d_comboa_radio_proc, 285, 94, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
18463 { d_comboa_radio_proc, 285, 104, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
18464 { d_comboacheck_proc, 285, 164, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
18465 { d_comboa_proc, 6, 27, 256, 176, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18466 { jwin_ctext_proc, 290, 176, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Only Show", NULL, NULL },
18467 { jwin_ctext_proc, 290, 186, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Current", NULL, NULL },
18468 { jwin_ctext_proc, 290, 196, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Layer", NULL, NULL },
18469 { jwin_ctext_proc, 290, 122, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Thumbnail", NULL, NULL },
18470 { jwin_frame_proc, 280, 132, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18471 { d_comboat_proc, 282, 134, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18472
18473 //21
18474 { d_orgcomboa_proc, 106, 212, 21, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Org", NULL, NULL },
18475 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18476 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18477 };
18478
18479 int32_t getcurrentcomboalias()
18480 {
18481 return editcomboa_dlg[5].d1;
18482 }
18483
18484 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c)
18485 {
18486 int32_t temp = layer_cnt;
18487 int32_t ret = jwin_radiofont_proc(msg,d,c);
18488
18489 if(editcomboa_dlg[6].flags&D_SELECTED) layer_cnt=0;
18490 else if(editcomboa_dlg[7].flags&D_SELECTED) layer_cnt=1;
18491 else if(editcomboa_dlg[8].flags&D_SELECTED) layer_cnt=2;
18492 else if(editcomboa_dlg[9].flags&D_SELECTED) layer_cnt=3;
18493 else if(editcomboa_dlg[10].flags&D_SELECTED) layer_cnt=4;
18494 else if(editcomboa_dlg[11].flags&D_SELECTED) layer_cnt=5;
18495 else if(editcomboa_dlg[12].flags&D_SELECTED) layer_cnt=6;
18496
18497 if(temp != layer_cnt)
18498 {
18499 return D_REDRAW;
18500 }
18501
18502 return ret;
18503 }
18504
18505 int32_t set_comboaradio(byte layermask)
18506 {
18507 if(editcomboa_dlg[7].flags&D_SELECTED) editcomboa_dlg[7].flags &= ~D_SELECTED;
18508
18509 if(editcomboa_dlg[8].flags&D_SELECTED) editcomboa_dlg[8].flags &= ~D_SELECTED;
18510
18511 if(editcomboa_dlg[9].flags&D_SELECTED) editcomboa_dlg[9].flags &= ~D_SELECTED;
18512
18513 if(editcomboa_dlg[10].flags&D_SELECTED) editcomboa_dlg[10].flags &= ~D_SELECTED;
18514
18515 if(editcomboa_dlg[11].flags&D_SELECTED) editcomboa_dlg[11].flags &= ~D_SELECTED;
18516
18517 if(editcomboa_dlg[12].flags&D_SELECTED) editcomboa_dlg[12].flags &= ~D_SELECTED;
18518
18519 if(!(layermask&1)) editcomboa_dlg[7].flags |= D_DISABLED;
18520 else editcomboa_dlg[7].flags &= ~D_DISABLED;
18521
18522 if(!(layermask&2)) editcomboa_dlg[8].flags |= D_DISABLED;
18523 else editcomboa_dlg[8].flags &= ~D_DISABLED;
18524
18525 if(!(layermask&4)) editcomboa_dlg[9].flags |= D_DISABLED;
18526 else editcomboa_dlg[9].flags &= ~D_DISABLED;
18527
18528 if(!(layermask&8)) editcomboa_dlg[10].flags |= D_DISABLED;
18529 else editcomboa_dlg[10].flags &= ~D_DISABLED;
18530
18531 if(!(layermask&16)) editcomboa_dlg[11].flags |= D_DISABLED;
18532 else editcomboa_dlg[11].flags &= ~D_DISABLED;
18533
18534 if(!(layermask&32)) editcomboa_dlg[12].flags |= D_DISABLED;
18535 else editcomboa_dlg[12].flags &= ~D_DISABLED;
18536
18537 editcomboa_dlg[6].flags |= D_SELECTED;
18538 layer_cnt=0;
18539 return 1;
18540 }
18541
18542 int32_t onEditComboPool()
18543 {
18544 call_cpool_dlg(combo_pool_pos);
18545 return D_O_K;
18546 }
18547 int32_t onEditAutoCombo()
18548 {
18549 call_autocombo_dlg(combo_auto_pos);
18550 return D_O_K;
18551 }
18552 int32_t onEditComboAlias()
18553 {
18554 comboa_cnt = combo_apos;
18555 reset_combo_animations();
18556 reset_combo_animations2();
18557
18558 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18559 temp_aliases[i] = combo_aliases[i];
18560
18561 editcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18562 set_comboaradio(temp_aliases[comboa_cnt].layermask);
18563 editcomboa_dlg[5].d1 = comboa_cnt;
18564
18565 bool small_d1 = editcomboa_dlg[0].d1==0;
18566 large_dialog(editcomboa_dlg,2);
18567
18568 if(small_d1)
18569 {
18570 for(int32_t i=6; i<=12; i++)
18571 {
18572 editcomboa_dlg[i].w=30*1.5;
18573 editcomboa_dlg[i].h=9*1.5;
18574 }
18575
18576 editcomboa_dlg[13].w=17*1.5;
18577 editcomboa_dlg[13].h=9*1.5;
18578 editcomboa_dlg[4].w=81*1.5;
18579 editcomboa_dlg[4].h=21*1.5;
18580 editcomboa_dlg[4].dp2=get_zc_font(font_lfont_l);
18581 editcomboa_dlg[21].w=21*1.5;
18582 editcomboa_dlg[21].h=21*1.5;
18583 editcomboa_dlg[21].dp2=get_zc_font(font_lfont_l);
18584 }
18585
18586 int32_t ret=do_zqdialog(editcomboa_dlg,-1);
18587
18588 if(ret==1)
18589 {
18590 saved=false;
18591
18592 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18593 combo_aliases[i] = temp_aliases[i];
18594 }
18595
18596 setup_combo_animations();
18597 setup_combo_animations2();
18598 return D_O_K;
18599 }
18600 void call_calias_dlg(int index)
18601 {
18602 combo_apos = comboa_cnt = index;
18603 onEditComboAlias();
18604 }
18605
18606 static char ffcombo_str_buf[MAXFFCS];
18607 static char fflink_str_buf[MAXFFCS];
18608
18609 BITMAP* ffcur;
18610
18611 const char *ffcombolist(int32_t index, int32_t *list_size)
18612 {
18613 if(index>=0)
18614 {
18615 bound(index,0,MAXFFCS-1);
18616 sprintf(ffcombo_str_buf,"%d",index+1);
18617 return ffcombo_str_buf;
18618 }
18619
18620 *list_size=MAXFFCS;
18621 return NULL;
18622 }
18623
18624 12 static ListData ffcombo_list(ffcombolist, &font);
18625
18626 static DIALOG ffcombo_sel_dlg[] =
18627 {
18628 12 { jwin_win_proc, 0, 0, 200, 179, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Choose Freeform Combo", NULL, NULL },
18629 12 { jwin_button_proc, 35, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
18630 12 { jwin_button_proc, 104, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
18631 12 { d_ffcombolist_proc, 11, 24, 49, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &ffcombo_list, NULL, NULL },
18632 12 { d_comboframe_proc, 68, 23, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18633 12 { d_bitmap_proc, 70, 25, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18634 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18635 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18636 };
18637
18638 int32_t d_ffcombolist_proc(int32_t msg,DIALOG *d,int32_t c)
18639 {
18640 int32_t ret = jwin_droplist_proc(msg,d,c);
18641 int32_t d1 = d->d1;
18642 int32_t x=ffcombo_sel_dlg[0].x;
18643 int32_t y=ffcombo_sel_dlg[0].y;
18644 FONT *tempfont=(font);
18645 int32_t x2=text_length(tempfont, "Move Delay:")+4;
18646
18647 switch(msg)
18648 {
18649 case MSG_DRAW:
18650 if(!ffcur) return D_O_K;
18651
18652 BITMAP *buf = create_bitmap_ex(8,16,16);
18653
18654 if(buf)
18655 {
18656 clear_bitmap(buf);
18657 putcombo(buf,0,0,Map.CurrScr()->ffcs[d1].data,Map.CurrScr()->ffcs[d1].cset);
18658 stretch_blit(buf, ffcur, 0,0, 16, 16, 0, 0, ffcur->w, ffcur->h);
18659 destroy_bitmap(buf);
18660 }
18661
18662 object_message(&ffcombo_sel_dlg[5],MSG_DRAW,0);
18663
18664 int32_t xd = x+int32_t(68*1.5);
18665 int32_t y2 = y+int32_t(55*1.5);
18666 int32_t yd = 9;
18667
18668 rectfill(screen,xd,y2,xd+x2+100,y2+yd*14,jwin_pal[jcBOX]);
18669
18670 textprintf_ex(screen,tempfont,xd,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo #:");
18671 textprintf_ex(screen,tempfont,xd+x2,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].data);
18672
18673 textprintf_ex(screen,tempfont,xd,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"CSet #:");
18674 textprintf_ex(screen,tempfont,xd+x2,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].cset);
18675
18676 textprintf_ex(screen,tempfont,xd,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Pos:");
18677 textprintf_ex(screen,tempfont,xd+x2,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].x.getFloat());
18678
18679 textprintf_ex(screen,tempfont,xd,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Pos:");
18680 textprintf_ex(screen,tempfont,xd+x2,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].y.getFloat());
18681
18682 textprintf_ex(screen,tempfont,xd,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Speed:");
18683 textprintf_ex(screen,tempfont,xd+x2,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vx.getFloat());
18684
18685 textprintf_ex(screen,tempfont,xd,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Speed:");
18686 textprintf_ex(screen,tempfont,xd+x2,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vy.getFloat());
18687
18688 textprintf_ex(screen,tempfont,xd,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Accel:");
18689 textprintf_ex(screen,tempfont,xd+x2,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ax.getFloat());
18690
18691 textprintf_ex(screen,tempfont,xd,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Accel:");
18692 textprintf_ex(screen,tempfont,xd+x2,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ay.getFloat());
18693
18694 textprintf_ex(screen,tempfont,xd,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Linked To:");
18695 textprintf_ex(screen,tempfont,xd+x2,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].link);
18696
18697 textprintf_ex(screen,tempfont,xd,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Move Delay:");
18698 textprintf_ex(screen,tempfont,xd+x2,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].delay);
18699
18700 textprintf_ex(screen,tempfont,xd,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo W:");
18701 textprintf_ex(screen,tempfont,xd+x2,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectWidth(d1)));
18702
18703 textprintf_ex(screen,tempfont,xd,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo H:");
18704 textprintf_ex(screen,tempfont,xd+x2,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectHeight(d1)));
18705
18706 textprintf_ex(screen,tempfont,xd,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile W:");
18707 textprintf_ex(screen,tempfont,xd+x2,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileWidth(d1)));
18708
18709 textprintf_ex(screen,tempfont,xd,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile H:");
18710 textprintf_ex(screen,tempfont,xd+x2,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileHeight(d1)));
18711
18712 break;
18713 }
18714
18715 return ret;
18716 }
18717 int32_t onSelectFFCombo()
18718 {
18719 ffcombo_sel_dlg[0].dp2 = get_zc_font(font_lfont);
18720 ffcombo_sel_dlg[3].d1 = ff_combo;
18721 ffcur = create_bitmap_ex(8,32,32);
18722
18723 if(!ffcur) return D_O_K;
18724
18725 Map.CurrScr()->ensureFFC(MAXFFCS - 1);
18726 putcombo(ffcur,0,0,Map.CurrScr()->ffcs[ff_combo].data,Map.CurrScr()->ffcs[ff_combo].cset);
18727 ffcombo_sel_dlg[5].dp = ffcur;
18728
18729 bool resize = !(ffcombo_sel_dlg[0].d1);
18730 large_dialog(ffcombo_sel_dlg);
18731
18732 if(resize)
18733 {
18734 ffcombo_sel_dlg[5].x--;
18735 ffcombo_sel_dlg[5].y--;
18736 }
18737
18738 int32_t ret=do_zqdialog(ffcombo_sel_dlg,0);
18739
18740 while(ret==1)
18741 {
18742 ff_combo = ffcombo_sel_dlg[3].d1;
18743 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
18744 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
18745 call_ffc_dialog(ff_combo, scr, screen);
18746 ret=do_zqdialog(ffcombo_sel_dlg,0);
18747 }
18748
18749 destroy_bitmap(ffcur);
18750 return D_O_K;
18751 }
18752
18753 const char *globalscriptlist(int32_t index, int32_t *list_size);
18754 12 static ListData globalscript_list(globalscriptlist, &font);
18755 const char *playerscriptlist(int32_t index, int32_t *list_size);
18756 12 static ListData playerscript_list(playerscriptlist, &font);
18757
18758 const char *ffscriptlist(int32_t index, int32_t *list_size);
18759
18760 12 static ListData ffscript_list(ffscriptlist, &font);
18761
18762 char *strip_decimals(char *string)
18763 {
18764 int32_t len=(int32_t)strlen(string);
18765 char *src=(char *)malloc(len+1);
18766 char *tmpsrc=src;
18767 memcpy(src,string,len+1);
18768 memset(src,0,len+1);
18769
18770 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18771 {
18772 *tmpsrc=string[i];
18773
18774 if(*tmpsrc=='.')
18775 {
18776 while(string[i+1]=='.'&&i<=strlen(string))
18777 {
18778 i++;
18779 }
18780 }
18781
18782 tmpsrc++;
18783 }
18784
18785 memcpy(string,src,len);
18786 free(src);
18787 return string;
18788 }
18789
18790 // Unused??? -L 6/6/11
18791 char *clean_numeric_string(char *string)
18792 {
18793 bool found_sign=false;
18794 bool found_decimal=false;
18795 int32_t len=(int32_t)strlen(string);
18796 char *src=(char *)malloc(len+1);
18797 char *tmpsrc=src;
18798 memcpy(src,string,len+1);
18799 memset(src,0,len+1);
18800
18801 // strip out non-numerical characters
18802 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18803 {
18804 *tmpsrc=string[i];
18805
18806 if(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18807 {
18808 while(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18809 {
18810 i++;
18811 }
18812 }
18813
18814 tmpsrc++;
18815 }
18816
18817 len=(int32_t)strlen(src);
18818 char *src2=(char *)malloc(len+1);
18819 tmpsrc=src2;
18820 memcpy(src,src2,len+1);
18821 memset(src2,0,len+1);
18822
18823 // second purge
18824 for(size_t i=0; src[i]&&i<=strlen(src); i++)
18825 {
18826 *tmpsrc=src[i];
18827
18828 if(*tmpsrc=='-'||*tmpsrc=='+')
18829 {
18830 if(found_sign||found_decimal)
18831 {
18832 while(*tmpsrc=='-'||*tmpsrc=='+')
18833 {
18834 i++;
18835 }
18836 }
18837
18838 found_sign=true;
18839 }
18840
18841 if(*tmpsrc=='.')
18842 {
18843 if(found_decimal)
18844 {
18845 while(*tmpsrc=='.')
18846 {
18847 i++;
18848 }
18849 }
18850
18851 found_decimal=true;
18852 }
18853
18854 tmpsrc++;
18855 }
18856
18857 sprintf(string, "%s", src2);
18858 free(src);
18859 free(src2);
18860 return string;
18861 }
18862
18863 script_struct biglobal[NUMSCRIPTGLOBAL+1]; //global script
18864 int32_t biglobal_cnt = -1;
18865 script_struct biffs[NUMSCRIPTFFC]; //ff script
18866 int32_t biffs_cnt = -1;
18867 script_struct biitems[NUMSCRIPTITEM]; //item script
18868 int32_t biitems_cnt = -1;
18869 script_struct binpcs[NUMSCRIPTGUYS]; //npc script
18870 int32_t binpcs_cnt = -1;
18871
18872 script_struct bilweapons[NUMSCRIPTWEAPONS]; //lweapon script
18873 int32_t bilweapons_cnt = -1;
18874
18875 script_struct bieweapons[NUMSCRIPTWEAPONS]; //eweapon script
18876 int32_t bieweapons_cnt = -1;
18877
18878 script_struct bihero[NUMSCRIPTHERO]; //link script
18879 int32_t bihero_cnt = -1;
18880
18881 script_struct biscreens[NUMSCRIPTSCREEN]; //screen (screendata) script
18882 int32_t biscreens_cnt = -1;
18883
18884 script_struct bidmaps[NUMSCRIPTSDMAP]; //dmap (dmapdata) script
18885 int32_t bidmaps_cnt = -1;
18886
18887 script_struct biditemsprites[NUMSCRIPTSITEMSPRITE]; //dmap (dmapdata) script
18888 int32_t biitemsprites_cnt = -1;
18889
18890 script_struct bidcomboscripts[NUMSCRIPTSCOMBODATA]; //dmap (dmapdata) script
18891 int32_t bidcomboscripts_cnt = -1;
18892 //static char ffscript_str_buf[32];
18893
18894 void build_biglobal_list()
18895 {
18896 biglobal[0].first = "(None)";
18897 biglobal[0].second = -1;
18898 biglobal_cnt = 1;
18899
18900 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; ++i)
18901 {
18902 if(globalmap[i].scriptname.length()==0)
18903 continue;
18904
18905 stringstream ss;
18906 ss << globalmap[i].scriptname << " (" << i << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18907 biglobal[biglobal_cnt].first = ss.str();
18908 biglobal[biglobal_cnt].second = i;
18909 ++biglobal_cnt;
18910 }
18911
18912 // Blank out the rest of the list
18913 for(int32_t i=biglobal_cnt; i<NUMSCRIPTGLOBAL; ++i)
18914 {
18915 biglobal[i].first="";
18916 biglobal[i].second=-1;
18917 }
18918
18919 //Bubble sort! (doesn't account for gaps between scripts)
18920 for(int32_t i = 0; i < biglobal_cnt - 1; i++)
18921 {
18922 for(int32_t j = i + 1; j < biglobal_cnt; j++)
18923 {
18924 if(stricmp(biglobal[i].first.c_str(),biglobal[j].first.c_str()) > 0 && strcmp(biglobal[j].first.c_str(),""))
18925 zc_swap(biglobal[i],biglobal[j]);
18926 }
18927 }
18928
18929 biglobal_cnt = 0;
18930
18931 for(int32_t i = 0; i < NUMSCRIPTGLOBAL+1; ++i)
18932 if(biglobal[i].first.length() > 0)
18933 biglobal_cnt = i+1;
18934 }
18935
18936 6 void build_biffs_list()
18937 {
18938 6 biffs[0].first = "(None)";
18939 6 biffs[0].second = -1;
18940 6 biffs_cnt = 1;
18941
18942
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC - 1; i++)
18943 {
18944
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 2992 times.
3066 if(ffcmap[i].scriptname.length()==0)
18945 2992 continue;
18946
18947 74 stringstream ss;
18948
5/10
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 74 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 74 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 74 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 74 times.
✗ Branch 9 not taken.
74 ss << ffcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18949
1/2
✓ Branch 0 taken 74 times.
✗ Branch 1 not taken.
74 biffs[biffs_cnt].first = ss.str();
18950 74 biffs[biffs_cnt].second = i;
18951 74 biffs_cnt++;
18952 74 }
18953
18954 // Blank out the rest of the list
18955
2/2
✓ Branch 0 taken 2992 times.
✓ Branch 1 taken 6 times.
2998 for(int32_t i=biffs_cnt; i<NUMSCRIPTFFC; i++)
18956 {
18957 2992 biffs[i].first="";
18958 2992 biffs[i].second=-1;
18959 2992 }
18960
18961 //Bubble sort! (doesn't account for gaps between scripts)
18962
2/2
✓ Branch 0 taken 74 times.
✓ Branch 1 taken 6 times.
80 for(int32_t i = 0; i < biffs_cnt - 1; i++)
18963 {
18964
2/2
✓ Branch 0 taken 1308 times.
✓ Branch 1 taken 74 times.
1382 for(int32_t j = i + 1; j < biffs_cnt; j++)
18965 {
18966
3/4
✓ Branch 0 taken 527 times.
✓ Branch 1 taken 781 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 527 times.
1308 if(stricmp(biffs[i].first.c_str(),biffs[j].first.c_str()) > 0 && strcmp(biffs[j].first.c_str(),""))
18967 527 zc_swap(biffs[i],biffs[j]);
18968 1308 }
18969 74 }
18970
18971 6 biffs_cnt = 0;
18972
18973
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 6 times.
3078 for(int32_t i = 0; i < NUMSCRIPTFFC; i++)
18974
2/2
✓ Branch 0 taken 2992 times.
✓ Branch 1 taken 80 times.
3152 if(biffs[i].first.length() > 0)
18975 80 biffs_cnt = i+1;
18976 6 }
18977
18978 //npc scripts
18979 void build_binpcs_list()
18980 {
18981 binpcs[0].first = "(None)";
18982 binpcs[0].second = -1;
18983 binpcs_cnt = 1;
18984
18985 for(int32_t i = 0; i < NUMSCRIPTGUYS - 1; i++)
18986 {
18987 if(npcmap[i].scriptname.length()==0)
18988 continue;
18989
18990 stringstream ss;
18991 ss << npcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18992 binpcs[binpcs_cnt].first = ss.str();
18993 binpcs[binpcs_cnt].second = i;
18994 binpcs_cnt++;
18995 }
18996
18997 // Blank out the rest of the list
18998 for(int32_t i=binpcs_cnt; i<NUMSCRIPTGUYS; i++)
18999 {
19000 binpcs[i].first="";
19001 binpcs[i].second=-1;
19002 }
19003
19004 //Bubble sort! (doesn't account for gaps between scripts)
19005 for(int32_t i = 0; i < binpcs_cnt - 1; i++)
19006 {
19007 for(int32_t j = i + 1; j < binpcs_cnt; j++)
19008 {
19009 if(stricmp(binpcs[i].first.c_str(),binpcs[j].first.c_str()) > 0 && strcmp(binpcs[j].first.c_str(),""))
19010 zc_swap(binpcs[i],binpcs[j]);
19011 }
19012 }
19013
19014 binpcs_cnt = 0;
19015
19016 for(int32_t i = 0; i < NUMSCRIPTGUYS; i++)
19017 if(binpcs[i].first.length() > 0)
19018 binpcs_cnt = i+1;
19019 }
19020
19021
19022 //lweapon scripts
19023 void build_bilweapons_list()
19024 {
19025 bilweapons[0].first = "(None)";
19026 bilweapons[0].second = -1;
19027 bilweapons_cnt = 1;
19028
19029 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
19030 {
19031 if(lwpnmap[i].scriptname.length()==0)
19032 continue;
19033
19034 stringstream ss;
19035 ss << lwpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19036 bilweapons[bilweapons_cnt].first = ss.str();
19037 bilweapons[bilweapons_cnt].second = i;
19038 bilweapons_cnt++;
19039 }
19040
19041 // Blank out the rest of the list
19042 for(int32_t i=bilweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
19043 {
19044 bilweapons[i].first="";
19045 bilweapons[i].second=-1;
19046 }
19047
19048 //Bubble sort! (doesn't account for gaps between scripts)
19049 for(int32_t i = 0; i < bilweapons_cnt - 1; i++)
19050 {
19051 for(int32_t j = i + 1; j < bilweapons_cnt; j++)
19052 {
19053 if(stricmp(bilweapons[i].first.c_str(),bilweapons[j].first.c_str()) > 0 && strcmp(bilweapons[j].first.c_str(),""))
19054 zc_swap(bilweapons[i],bilweapons[j]);
19055 }
19056 }
19057
19058 bilweapons_cnt = 0;
19059
19060 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
19061 if(bilweapons[i].first.length() > 0)
19062 bilweapons_cnt = i+1;
19063 }
19064
19065 //eweapon scripts
19066 void build_bieweapons_list()
19067 {
19068 bieweapons[0].first = "(None)";
19069 bieweapons[0].second = -1;
19070 bieweapons_cnt = 1;
19071
19072 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
19073 {
19074 if(ewpnmap[i].scriptname.length()==0)
19075 continue;
19076
19077 stringstream ss;
19078 ss << ewpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19079 bieweapons[bieweapons_cnt].first = ss.str();
19080 bieweapons[bieweapons_cnt].second = i;
19081 bieweapons_cnt++;
19082 }
19083
19084 // Blank out the rest of the list
19085 for(int32_t i=bieweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
19086 {
19087 bieweapons[i].first="";
19088 bieweapons[i].second=-1;
19089 }
19090
19091 //Bubble sort! (doesn't account for gaps between scripts)
19092 for(int32_t i = 0; i < bieweapons_cnt - 1; i++)
19093 {
19094 for(int32_t j = i + 1; j < bieweapons_cnt; j++)
19095 {
19096 if(stricmp(bieweapons[i].first.c_str(),bieweapons[j].first.c_str()) > 0 && strcmp(bieweapons[j].first.c_str(),""))
19097 zc_swap(bieweapons[i],bieweapons[j]);
19098 }
19099 }
19100
19101 bieweapons_cnt = 0;
19102
19103 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
19104 if(bieweapons[i].first.length() > 0)
19105 bieweapons_cnt = i+1;
19106 }
19107
19108 //player scripts
19109 void build_bihero_list()
19110 {
19111 bihero[0].first = "(None)";
19112 bihero[0].second = -1;
19113 bihero_cnt = 1;
19114
19115 for(int32_t i = 0; i < NUMSCRIPTHERO - 1; i++)
19116 {
19117 if(playermap[i].scriptname.length()==0)
19118 continue;
19119
19120 stringstream ss;
19121 ss << playermap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19122 bihero[bihero_cnt].first = ss.str();
19123 bihero[bihero_cnt].second = i;
19124 bihero_cnt++;
19125 }
19126
19127 // Blank out the rest of the list
19128 for(int32_t i=bihero_cnt; i<NUMSCRIPTHERO; i++)
19129 {
19130 bihero[i].first="";
19131 bihero[i].second=-1;
19132 }
19133
19134 //Bubble sort! (doesn't account for gaps between scripts)
19135 for(int32_t i = 0; i < bihero_cnt - 1; i++)
19136 {
19137 for(int32_t j = i + 1; j < bihero_cnt; j++)
19138 {
19139 if(stricmp(bihero[i].first.c_str(),bihero[j].first.c_str()) > 0 && strcmp(bihero[j].first.c_str(),""))
19140 zc_swap(bihero[i],bihero[j]);
19141 }
19142 }
19143
19144 bihero_cnt = 0;
19145
19146 for(int32_t i = 0; i < NUMSCRIPTHERO; i++)
19147 if(bihero[i].first.length() > 0)
19148 bihero_cnt = i+1;
19149 }
19150
19151 //dmap scripts
19152 void build_bidmaps_list()
19153 {
19154 bidmaps[0].first = "(None)";
19155 bidmaps[0].second = -1;
19156 bidmaps_cnt = 1;
19157
19158 for(int32_t i = 0; i < NUMSCRIPTSDMAP - 1; i++)
19159 {
19160 if(dmapmap[i].scriptname.length()==0)
19161 continue;
19162
19163 stringstream ss;
19164 ss << dmapmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19165 bidmaps[bidmaps_cnt].first = ss.str();
19166 bidmaps[bidmaps_cnt].second = i;
19167 bidmaps_cnt++;
19168 }
19169
19170 // Blank out the rest of the list
19171 for(int32_t i=bidmaps_cnt; i<NUMSCRIPTSDMAP; i++)
19172 {
19173 bidmaps[i].first="";
19174 bidmaps[i].second=-1;
19175 }
19176
19177 //Bubble sort! (doesn't account for gaps between scripts)
19178 for(int32_t i = 0; i < bidmaps_cnt - 1; i++)
19179 {
19180 for(int32_t j = i + 1; j < bidmaps_cnt; j++)
19181 {
19182 if(stricmp(bidmaps[i].first.c_str(),bidmaps[j].first.c_str()) > 0 && strcmp(bidmaps[j].first.c_str(),""))
19183 zc_swap(bidmaps[i],bidmaps[j]);
19184 }
19185 }
19186
19187 bidmaps_cnt = 0;
19188
19189 for(int32_t i = 0; i < NUMSCRIPTSDMAP; i++)
19190 if(bidmaps[i].first.length() > 0)
19191 bidmaps_cnt = i+1;
19192 }
19193
19194 //screen scripts
19195 void build_biscreens_list()
19196 {
19197 biscreens[0].first = "(None)";
19198 biscreens[0].second = -1;
19199 biscreens_cnt = 1;
19200
19201 for(int32_t i = 0; i < NUMSCRIPTSCREEN - 1; i++)
19202 {
19203 if(screenmap[i].scriptname.length()==0)
19204 continue;
19205
19206 stringstream ss;
19207 ss << screenmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19208 biscreens[biscreens_cnt].first = ss.str();
19209 biscreens[biscreens_cnt].second = i;
19210 biscreens_cnt++;
19211 }
19212
19213 // Blank out the rest of the list
19214 for(int32_t i=biscreens_cnt; i<NUMSCRIPTSCREEN; i++)
19215 {
19216 biscreens[i].first="";
19217 biscreens[i].second=-1;
19218 }
19219
19220 //Bubble sort! (doesn't account for gaps between scripts)
19221 for(int32_t i = 0; i < biscreens_cnt - 1; i++)
19222 {
19223 for(int32_t j = i + 1; j < biscreens_cnt; j++)
19224 {
19225 if(stricmp(biscreens[i].first.c_str(),biscreens[j].first.c_str()) > 0 && strcmp(biscreens[j].first.c_str(),""))
19226 zc_swap(biscreens[i],biscreens[j]);
19227 }
19228 }
19229
19230 biscreens_cnt = 0;
19231
19232 for(int32_t i = 0; i < NUMSCRIPTSCREEN; i++)
19233 if(biscreens[i].first.length() > 0)
19234 biscreens_cnt = i+1;
19235 }
19236
19237 //screen scripts
19238 void build_biitemsprites_list()
19239 {
19240 biditemsprites[0].first = "(None)";
19241 biditemsprites[0].second = -1;
19242 biitemsprites_cnt = 1;
19243
19244 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE - 1; i++)
19245 {
19246 if(itemspritemap[i].scriptname.length()==0)
19247 continue;
19248
19249 stringstream ss;
19250 ss << itemspritemap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19251 biditemsprites[biitemsprites_cnt].first = ss.str();
19252 biditemsprites[biitemsprites_cnt].second = i;
19253 biitemsprites_cnt++;
19254 }
19255
19256 // Blank out the rest of the list
19257 for(int32_t i=biitemsprites_cnt; i<NUMSCRIPTSITEMSPRITE; i++)
19258 {
19259 biditemsprites[i].first="";
19260 biditemsprites[i].second=-1;
19261 }
19262
19263 //Bubble sort! (doesn't account for gaps between scripts)
19264 for(int32_t i = 0; i < biitemsprites_cnt - 1; i++)
19265 {
19266 for(int32_t j = i + 1; j < biitemsprites_cnt; j++)
19267 {
19268 if(stricmp(biditemsprites[i].first.c_str(),biditemsprites[j].first.c_str()) > 0 && strcmp(biditemsprites[j].first.c_str(),""))
19269 zc_swap(biditemsprites[i],biditemsprites[j]);
19270 }
19271 }
19272
19273 biitemsprites_cnt = 0;
19274
19275 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE; i++)
19276 if(biditemsprites[i].first.length() > 0)
19277 biitemsprites_cnt = i+1;
19278 }
19279
19280 6 void build_biitems_list()
19281 {
19282 6 biitems[0].first = "(None)";
19283 6 biitems[0].second = -1;
19284 6 biitems_cnt = 1;
19285
19286
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM - 1; i++, biitems_cnt++)
19287 {
19288 1530 stringstream ss;
19289
19290
4/6
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1530 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1517 times.
1530 if(!itemmap[i].isEmpty())
19291
5/10
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
13 ss << itemmap[i].scriptname << " (" << i+1 << ")";
19292
19293
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 biitems[biitems_cnt].first = ss.str();
19294 1530 biitems[biitems_cnt].second = i;
19295 1530 }
19296
19297
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < biitems_cnt - 1; i++)
19298 {
19299
2/2
✓ Branch 0 taken 195840 times.
✓ Branch 1 taken 1530 times.
197370 for(int32_t j = i + 1; j < biitems_cnt; j++)
19300 {
19301
4/4
✓ Branch 0 taken 4760 times.
✓ Branch 1 taken 191080 times.
✓ Branch 2 taken 4757 times.
✓ Branch 3 taken 3 times.
195840 if(stricmp(biitems[i].first.c_str(), biitems[j].first.c_str()) > 0 && strcmp(biitems[j].first.c_str(),""))
19302 3 zc_swap(biitems[i], biitems[j]);
19303 195840 }
19304 1530 }
19305
19306 6 biitems_cnt = 0;
19307
19308
2/2
✓ Branch 0 taken 1536 times.
✓ Branch 1 taken 6 times.
1542 for(int32_t i = 0; i < NUMSCRIPTITEM; i++)
19309
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 19 times.
1555 if(biitems[i].first.length() > 0)
19310 19 biitems_cnt = i+1;
19311 6 }
19312
19313
19314 //dmap scripts
19315 void build_bidcomboscripts_list()
19316 {
19317 bidcomboscripts[0].first = "(None)";
19318 bidcomboscripts[0].second = -1;
19319 bidcomboscripts_cnt = 1;
19320
19321 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA - 1; i++)
19322 {
19323 if(comboscriptmap[i].scriptname.length()==0)
19324 continue;
19325
19326 stringstream ss;
19327 ss << comboscriptmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19328 bidcomboscripts[bidcomboscripts_cnt].first = ss.str();
19329 bidcomboscripts[bidcomboscripts_cnt].second = i;
19330 bidcomboscripts_cnt++;
19331 }
19332
19333 // Blank out the rest of the list
19334 for(int32_t i=bidcomboscripts_cnt; i<NUMSCRIPTSCOMBODATA; i++)
19335 {
19336 bidcomboscripts[i].first="";
19337 bidcomboscripts[i].second=-1;
19338 }
19339
19340 //Bubble sort! (doesn't account for gaps between scripts)
19341 for(int32_t i = 0; i < bidcomboscripts_cnt - 1; i++)
19342 {
19343 for(int32_t j = i + 1; j < bidcomboscripts_cnt; j++)
19344 {
19345 if(stricmp(bidcomboscripts[i].first.c_str(),bidcomboscripts[j].first.c_str()) > 0 && strcmp(bidcomboscripts[j].first.c_str(),""))
19346 zc_swap(bidcomboscripts[i],bidcomboscripts[j]);
19347 }
19348 }
19349
19350 bidcomboscripts_cnt = 0;
19351
19352 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA; i++)
19353 if(bidcomboscripts[i].first.length() > 0)
19354 bidcomboscripts_cnt = i+1;
19355 }
19356
19357
19358 const char *globalscriptlist(int32_t index, int32_t *list_size)
19359 {
19360 if(index < 0)
19361 {
19362 *list_size = biglobal_cnt;
19363 return NULL;
19364 }
19365
19366 return biglobal[index].first.c_str();
19367 }
19368
19369 const char *ffscriptlist(int32_t index, int32_t *list_size)
19370 {
19371 if(index < 0)
19372 {
19373 *list_size = biffs_cnt;
19374 return NULL;
19375 }
19376
19377 return biffs[index].first.c_str();
19378 }
19379
19380 const char *playerscriptlist(int32_t index, int32_t *list_size)
19381 {
19382 if(index < 0)
19383 {
19384 *list_size = bihero_cnt;
19385 return NULL;
19386 }
19387
19388 return bihero[index].first.c_str();
19389 }
19390
19391 const char *lweaponscriptlist(int32_t index, int32_t *list_size)
19392 {
19393 if(index < 0)
19394 {
19395 *list_size = bilweapons_cnt;
19396 return NULL;
19397 }
19398
19399 return bilweapons[index].first.c_str();
19400 }
19401
19402 const char *npcscriptlist(int32_t index, int32_t *list_size)
19403 {
19404 if(index < 0)
19405 {
19406 *list_size = binpcs_cnt;
19407 return NULL;
19408 }
19409
19410 return binpcs[index].first.c_str();
19411 }
19412
19413 static char itemscript_str_buf[32];
19414
19415 char *itemscriptlist(int32_t index, int32_t *list_size)
19416 {
19417 if(index>=0)
19418 {
19419 bound(index,0,255);
19420 sprintf(itemscript_str_buf,"%d: %s",index, ffcmap[index-1].scriptname.c_str());
19421 return itemscript_str_buf;
19422 }
19423
19424 *list_size=256;
19425 return NULL;
19426 }
19427
19428 static char ffscript_str_buf2[32];
19429
19430 const char *ffscriptlist2(int32_t index, int32_t *list_size)
19431 {
19432 if(index>=0)
19433 {
19434 char buf[20];
19435 bound(index,0,510);
19436
19437 if(ffcmap[index].scriptname=="")
19438 strcpy(buf, "<none>");
19439 else
19440 {
19441 strncpy(buf, ffcmap[index].scriptname.c_str(), 19);
19442 buf[19]='\0';
19443 }
19444
19445 sprintf(ffscript_str_buf2,"%d: %s",index+1, buf);
19446 return ffscript_str_buf2;
19447 }
19448
19449 *list_size=511;
19450 return NULL;
19451 }
19452
19453 static char itemscript_str_buf2[32];
19454
19455 const char *itemscriptlist2(int32_t index, int32_t *list_size)
19456 {
19457 if(index>=0)
19458 {
19459 char buf[20];
19460 bound(index,0,254);
19461
19462 if(itemmap[index].scriptname=="")
19463 strcpy(buf, "<none>");
19464 else
19465 {
19466 strncpy(buf, itemmap[index].scriptname.c_str(), 19);
19467 buf[19]='\0';
19468 }
19469
19470 sprintf(itemscript_str_buf2,"%d: %s",index+1, buf);
19471 return itemscript_str_buf2;
19472 }
19473
19474 *list_size=255;
19475 return NULL;
19476 }
19477
19478
19479 static char comboscript_str_buf2[32];
19480 const char *comboscriptlist2(int32_t index, int32_t *list_size)
19481 {
19482 if(index>=0)
19483 {
19484 char buf[20];
19485 bound(index,0,254);
19486
19487 if(comboscriptmap[index].scriptname=="")
19488 strcpy(buf, "<none>");
19489 else
19490 {
19491 strncpy(buf, comboscriptmap[index].scriptname.c_str(), 19);
19492 buf[19]='\0';
19493 }
19494
19495 sprintf(comboscript_str_buf2,"%d: %s",index+1, buf);
19496 return comboscript_str_buf2;
19497 }
19498
19499 *list_size=255;
19500 return NULL;
19501 }
19502
19503 static char gscript_str_buf2[40];
19504
19505 const char *gscriptlist2(int32_t index, int32_t *list_size)
19506 {
19507 if(index >= 0)
19508 {
19509 bound(index,0,3);
19510
19511 char buf[20];
19512
19513 if(globalmap[index].scriptname == "")
19514 strcpy(buf, "<none>");
19515 else
19516 {
19517 strncpy(buf, globalmap[index].scriptname.c_str(), 19);
19518 buf[19]='\0';
19519 }
19520
19521 switch(index)
19522 {
19523 case GLOBAL_SCRIPT_INIT:
19524 sprintf(gscript_str_buf2,"Initialization: %s", buf); break;
19525 case GLOBAL_SCRIPT_GAME:
19526 sprintf(gscript_str_buf2,"Active: %s", buf); break;
19527 case GLOBAL_SCRIPT_END:
19528 sprintf(gscript_str_buf2,"onExit: %s", buf); break;
19529 case GLOBAL_SCRIPT_ONSAVELOAD:
19530 sprintf(gscript_str_buf2,"onSaveLoad: %s", buf); break;
19531 case GLOBAL_SCRIPT_ONLAUNCH:
19532 sprintf(gscript_str_buf2,"onLaunch: %s", buf); break;
19533 case GLOBAL_SCRIPT_ONCONTGAME:
19534 sprintf(gscript_str_buf2,"onContGame: %s", buf); break;
19535 case GLOBAL_SCRIPT_F6:
19536 sprintf(gscript_str_buf2,"onF6Menu: %s", buf); break;
19537 case GLOBAL_SCRIPT_ONSAVE:
19538 sprintf(gscript_str_buf2,"onSave: %s", buf); break;
19539 }
19540
19541 return gscript_str_buf2;
19542 }
19543
19544 if(list_size != NULL)
19545 *list_size=4;
19546
19547 return NULL;
19548 }
19549
19550 static int32_t as_ffc_list[] = { 4, 5, 6, -1};
19551 static int32_t as_global_list[] = { 7, 8, 9, -1}; //Why does putting 15 in here not place my message only on the global tab? ~Joe
19552 static int32_t as_item_list[] = { 10, 11, 12, -1};
19553 static int32_t as_npc_list[] = { 18, 19, 20, -1}; //npc scripts TAB
19554 static int32_t as_lweapon_list[] = { 21, 22, 23, -1}; //lweapon scripts TAB
19555 static int32_t as_eweapon_list[] = { 24, 25, 26, -1}; //eweapon scripts TAB
19556 static int32_t as_hero_list[] = { 27, 28, 29, -1}; //hero scripts TAB
19557 static int32_t as_screen_list[] = { 30, 31, 32, -1}; //screendata scripts TAB
19558 static int32_t as_dmap_list[] = { 33, 34, 35, -1}; //dmapdata scripts TAB
19559 static int32_t as_itemsprite_list[] = { 36, 37, 38, -1}; //dmapdata scripts TAB
19560 static int32_t as_comboscript_list[] = { 39, 40, 41, -1}; //combodata scripts TAB
19561 static int32_t as_genericscript_list[] = { 45, 46, 47, -1}; //generic scripts TAB
19562 static int32_t as_subscreenscript_list[] = { 48, 49, 50, -1}; //generic scripts TAB
19563
19564 static TABPANEL assignscript_tabs[] =
19565 {
19566 // (text)
19567 { (char *)"FFC", D_SELECTED, as_ffc_list, 0, NULL },
19568 { (char *)"Global", 0, as_global_list, 0, NULL },
19569 { (char *)"Item", 0, as_item_list, 0, NULL },
19570 { (char *)"NPC", 0, as_npc_list, 0, NULL },
19571 { (char *)"LWeapon", 0, as_lweapon_list, 0, NULL },
19572 { (char *)"EWeapon", 0, as_eweapon_list, 0, NULL },
19573 { (char *)"Hero", 0, as_hero_list, 0, NULL },
19574 { (char *)"DMap", 0, as_dmap_list, 0, NULL },
19575 { (char *)"Screen", 0, as_screen_list, 0, NULL },
19576 { (char *)"Item Sprite", 0, as_itemsprite_list, 0, NULL },
19577 { (char *)"Combo", 0, as_comboscript_list, 0, NULL },
19578 { (char *)"Generic", 0, as_genericscript_list, 0, NULL },
19579 { (char *)"Subscreen", 0, as_subscreenscript_list, 0, NULL },
19580 { NULL, 0, NULL, 0, NULL }
19581 };
19582
19583 const char *assignffclist(int32_t index, int32_t *list_size)
19584 {
19585 if(index<0)
19586 {
19587 *list_size = (int32_t)ffcmap.size();
19588 return NULL;
19589 }
19590
19591 return ffcmap[index].output.c_str();
19592 }
19593
19594 const char *assigngloballist(int32_t index, int32_t *list_size)
19595 {
19596 if(index<0)
19597 {
19598 *list_size = (int32_t)globalmap.size();
19599 return NULL;
19600 }
19601
19602 return globalmap[index].output.c_str();
19603 }
19604
19605 const char *assigncombolist(int32_t index, int32_t *list_size)
19606 {
19607 if(index<0)
19608 {
19609 *list_size = (int32_t)comboscriptmap.size();
19610 return NULL;
19611 }
19612
19613 return comboscriptmap[index].output.c_str();
19614 }
19615
19616 const char *assigngenericlist(int32_t index, int32_t *list_size)
19617 {
19618 if(index<0)
19619 {
19620 *list_size = ((int32_t)genericmap.size());
19621 return NULL;
19622 }
19623
19624 return genericmap[index].output.c_str();
19625 }
19626
19627 const char *assignsubscreenlist(int32_t index, int32_t *list_size)
19628 {
19629 if(index<0)
19630 {
19631 *list_size = ((int32_t)subscreenmap.size());
19632 return NULL;
19633 }
19634
19635 return subscreenmap[index].output.c_str();
19636 }
19637
19638 const char *assignitemlist(int32_t index, int32_t *list_size)
19639 {
19640 if(index<0)
19641 {
19642 *list_size = (int32_t)itemmap.size();
19643 return NULL;
19644 }
19645
19646 return itemmap[index].output.c_str();
19647 }
19648 const char *assignnpclist(int32_t index, int32_t *list_size)
19649 {
19650 if(index<0)
19651 {
19652 *list_size = (int32_t)npcmap.size();
19653 return NULL;
19654 }
19655
19656 return npcmap[index].output.c_str();
19657 }
19658
19659 const char *assignlweaponlist(int32_t index, int32_t *list_size)
19660 {
19661 if(index<0)
19662 {
19663 *list_size = (int32_t)lwpnmap.size();
19664 return NULL;
19665 }
19666
19667 return lwpnmap[index].output.c_str();
19668 }
19669
19670 const char *assigneweaponlist(int32_t index, int32_t *list_size)
19671 {
19672 if(index<0)
19673 {
19674 *list_size = (int32_t)ewpnmap.size();
19675 return NULL;
19676 }
19677
19678 return ewpnmap[index].output.c_str();
19679 }
19680
19681 const char *assignplayerlist(int32_t index, int32_t *list_size)
19682 {
19683 if(index<0)
19684 {
19685 *list_size = (int32_t)playermap.size();
19686 return NULL;
19687 }
19688
19689 return playermap[index].output.c_str();
19690 }
19691
19692 const char *assigndmaplist(int32_t index, int32_t *list_size)
19693 {
19694 if(index<0)
19695 {
19696 *list_size = (int32_t)dmapmap.size();
19697 return NULL;
19698 }
19699
19700 return dmapmap[index].output.c_str();
19701 }
19702
19703 const char *assignscreenlist(int32_t index, int32_t *list_size)
19704 {
19705 if(index<0)
19706 {
19707 *list_size = (int32_t)screenmap.size();
19708 return NULL;
19709 }
19710
19711 return screenmap[index].output.c_str();
19712 }
19713
19714 const char *assignitemspritelist(int32_t index, int32_t *list_size)
19715 {
19716 if(index<0)
19717 {
19718 *list_size = (int32_t)itemspritemap.size();
19719 return NULL;
19720 }
19721
19722 return itemspritemap[index].output.c_str();
19723 }
19724
19725 const char *assignffcscriptlist(int32_t index, int32_t *list_size)
19726 {
19727 if(index<0)
19728 {
19729 *list_size = (int32_t)asffcscripts.size();
19730 return NULL;
19731 }
19732
19733 return asffcscripts[index].c_str();
19734 }
19735
19736 const char *assignglobalscriptlist(int32_t index, int32_t *list_size)
19737 {
19738 if(index<0)
19739 {
19740 *list_size = (int32_t)asglobalscripts.size();
19741 return NULL;
19742 }
19743
19744 return asglobalscripts[index].c_str();
19745 }
19746
19747 const char *assignitemscriptlist(int32_t index, int32_t *list_size)
19748 {
19749 if(index<0)
19750 {
19751 *list_size = (int32_t)asitemscripts.size();
19752 return NULL;
19753 }
19754
19755 return asitemscripts[index].c_str();
19756 }
19757
19758 const char *assignnpcscriptlist(int32_t index, int32_t *list_size)
19759 {
19760 if(index<0)
19761 {
19762 *list_size = (int32_t)asnpcscripts.size();
19763 return NULL;
19764 }
19765
19766 return asnpcscripts[index].c_str();
19767 }
19768
19769 const char *assignlweaponscriptlist(int32_t index, int32_t *list_size)
19770 {
19771 if(index<0)
19772 {
19773 *list_size = (int32_t)aslweaponscripts.size();
19774 return NULL;
19775 }
19776
19777 return aslweaponscripts[index].c_str();
19778 }
19779
19780 const char *assigneweaponscriptlist(int32_t index, int32_t *list_size)
19781 {
19782 if(index<0)
19783 {
19784 *list_size = (int32_t)aseweaponscripts.size();
19785 return NULL;
19786 }
19787
19788 return aseweaponscripts[index].c_str();
19789 }
19790
19791 const char *assignplayerscriptlist(int32_t index, int32_t *list_size)
19792 {
19793 if(index<0)
19794 {
19795 *list_size = (int32_t)asplayerscripts.size();
19796 return NULL;
19797 }
19798
19799 return asplayerscripts[index].c_str();
19800 }
19801
19802 const char *assigndmapscriptlist(int32_t index, int32_t *list_size)
19803 {
19804 if(index<0)
19805 {
19806 *list_size = (int32_t)asdmapscripts.size();
19807 return NULL;
19808 }
19809
19810 return asdmapscripts[index].c_str();
19811 }
19812
19813 const char *assignscreenscriptlist(int32_t index, int32_t *list_size)
19814 {
19815 if(index<0)
19816 {
19817 *list_size = (int32_t)asscreenscripts.size();
19818 return NULL;
19819 }
19820
19821 return asscreenscripts[index].c_str();
19822 }
19823
19824 const char *assignitemspritescriptlist(int32_t index, int32_t *list_size)
19825 {
19826 if(index<0)
19827 {
19828 *list_size = (int32_t)asitemspritescripts.size();
19829 return NULL;
19830 }
19831
19832 return asitemspritescripts[index].c_str();
19833 }
19834
19835 const char *assigncomboscriptlist(int32_t index, int32_t *list_size)
19836 {
19837 if(index<0)
19838 {
19839 *list_size = (int32_t)ascomboscripts.size();
19840 return NULL;
19841 }
19842
19843 return ascomboscripts[index].c_str();
19844 }
19845
19846 const char *assigngenericscriptlist(int32_t index, int32_t *list_size)
19847 {
19848 if(index<0)
19849 {
19850 *list_size = (int32_t)asgenericscripts.size();
19851 return NULL;
19852 }
19853
19854 return asgenericscripts[index].c_str();
19855 }
19856
19857 const char *assignsubscreenscriptlist(int32_t index, int32_t *list_size)
19858 {
19859 if(index<0)
19860 {
19861 *list_size = (int32_t)assubscreenscripts.size();
19862 return NULL;
19863 }
19864
19865 return assubscreenscripts[index].c_str();
19866 }
19867
19868 12 static ListData assignffc_list(assignffclist, &font);
19869 12 static ListData assignffcscript_list(assignffcscriptlist, &font);
19870 12 static ListData assignglobal_list(assigngloballist, &font);
19871 12 static ListData assignglobalscript_list(assignglobalscriptlist, &font);
19872 12 static ListData assignitem_list(assignitemlist, &font);
19873 12 static ListData assignitemscript_list(assignitemscriptlist, &font);
19874 12 static ListData assignnpc_list(assignnpclist, &font);
19875 12 static ListData assignnpcscript_list(assignnpcscriptlist, &font);
19876 12 static ListData assignlweapon_list(assignlweaponlist, &font);
19877 12 static ListData assignlweaponscript_list(assignlweaponscriptlist, &font);
19878 12 static ListData assigneweapon_list(assigneweaponlist, &font);
19879 12 static ListData assigneweaponscript_list(assigneweaponscriptlist, &font);
19880
19881 12 static ListData assignplayer_list(assignplayerlist, &font);
19882 12 static ListData assignplayerscript_list(assignplayerscriptlist, &font);
19883
19884 12 static ListData assigndmap_list(assigndmaplist, &font);
19885 12 static ListData assigndmapscript_list(assigndmapscriptlist, &font);
19886
19887 12 static ListData assignscreen_list(assignscreenlist, &font);
19888 12 static ListData assignscreenscript_list(assignscreenscriptlist, &font);
19889
19890 12 static ListData assignitemsprite_list(assignitemspritelist, &font);
19891 12 static ListData assignitemspritescript_list(assignitemspritescriptlist, &font);
19892
19893 12 static ListData assigncombo_list(assigncombolist, &font);
19894 12 static ListData assigncomboscript_list(assigncomboscriptlist, &font);
19895
19896 12 static ListData assigngeneric_list(assigngenericlist, &font);
19897 12 static ListData assigngenericscript_list(assigngenericscriptlist, &font);
19898
19899 12 static ListData assignsubscreen_list(assignsubscreenlist, &font);
19900 12 static ListData assignsubscreenscript_list(assignsubscreenscriptlist, &font);
19901
19902 static DIALOG assignscript_dlg[] =
19903 {
19904 // x y w h fg bg key flags d1 d2 dp
19905 12 { jwin_win_proc, 0, 0, 330, 236, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Assign Compiled Script", NULL, NULL },
19906 12 { jwin_tab_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, (void*)assignscript_dlg },
19907 12 { jwin_button_proc, 251, 207, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
19908 12 { jwin_button_proc, 182, 207, 61, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
19909 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffc_list, NULL, NULL },
19910 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffcscript_list, NULL, NULL },
19911 //6
19912 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19913 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobal_list, NULL, NULL },
19914 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobalscript_list, NULL, NULL },
19915 //9
19916 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19917 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitem_list, NULL, NULL },
19918 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemscript_list, NULL, NULL },
19919 //12
19920 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19921 //13
19922 12 { jwin_check_proc, 22, 211, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Output ZASM code to allegro.log", NULL, NULL },
19923 12 { jwin_text_proc, 22, 178, 90, 24, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19924 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19925 //16
19926 12 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19927 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
19928 //npc scripts
19929 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpc_list, NULL, NULL },
19930 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpcscript_list, NULL, NULL },
19931 //20
19932 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19933 //21
19934 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweapon_list, NULL, NULL },
19935 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweaponscript_list, NULL, NULL },
19936 //23
19937 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19938 //24
19939 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweapon_list, NULL, NULL },
19940 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweaponscript_list, NULL, NULL },
19941 //26
19942 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19943 //27
19944 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayer_list, NULL, NULL },
19945 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayerscript_list, NULL, NULL },
19946 //29
19947 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19948 //30
19949 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreen_list, NULL, NULL },
19950 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreenscript_list, NULL, NULL },
19951 //32
19952 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19953 //33
19954 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmap_list, NULL, NULL },
19955 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmapscript_list, NULL, NULL },
19956 //35
19957 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19958 //36
19959 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemsprite_list, NULL, NULL },
19960 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemspritescript_list, NULL, NULL },
19961 //38
19962 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19963
19964 //39
19965 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncombo_list, NULL, NULL },
19966 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncomboscript_list, NULL, NULL },
19967 //41
19968 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19969 12 { jwin_button_proc, 78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19970 12 { jwin_button_proc, 174+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19971 12 { jwin_button_proc, 87+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear", NULL, NULL },
19972 //45
19973 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngeneric_list, NULL, NULL },
19974 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngenericscript_list, NULL, NULL },
19975 //47
19976 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19977 //48
19978 12 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreen_list, NULL, NULL },
19979 12 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreenscript_list, NULL, NULL },
19980 //50
19981 12 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19982 12 { jwin_check_proc, 22, 221, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "...And output ZASM comments", NULL, NULL },
19983
19984 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
19985
19986 };
19987
19988 int32_t txtout(BITMAP* dest, const char* txt, int32_t x, int32_t y, bool disabled)
19989 {
19990 if(disabled)
19991 {
19992 gui_textout_ln(dest, font, (uint8_t*)txt, x+1, y+1, scheme[jcLIGHT], scheme[jcBOX], 0);
19993 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcMEDDARK], -1, 0);
19994 }
19995 else
19996 {
19997 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcBOXFG], scheme[jcBOX], 0);
19998 }
19999 }
20000
20001 int32_t jwin_zmeta_proc(int32_t msg, DIALOG *d, int32_t )
20002 {
20003 int32_t ret = D_O_K;
20004 ASSERT(d);
20005
20006 BITMAP* target = (msg==MSG_START ? NULL : screen);
20007 switch(msg)
20008 {
20009 case MSG_START:
20010 case MSG_DRAW:
20011 {
20012 FONT *oldfont = font;
20013
20014 if(d->dp2)
20015 {
20016 font = (FONT*)d->dp2;
20017 }
20018
20019 bool disabled = (d->flags & D_DISABLED) != 0;
20020 if(d->dp)
20021 {
20022 zasm_meta const& meta = *((zasm_meta*)d->dp);
20023 int32_t ind = -1;
20024 d->w = 0;
20025 if(!meta.valid())
20026 {
20027 d->w = txtout(target, "Invalid ZASM metadata found!", d->x, d->y, disabled);
20028 ++ind;
20029 }
20030
20031 int32_t t_w = 0;
20032 char buf[1024];
20033 memset(buf, 0, sizeof(buf));
20034 sprintf(buf, "ZASM Version: %d", meta.zasm_v);
20035 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20036 d->w = zc_max(d->w, t_w);
20037 memset(buf, 0, sizeof(buf));
20038 sprintf(buf, "Metadata Version: %d", meta.meta_v);
20039 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20040 d->w = zc_max(d->w, t_w);
20041 memset(buf, 0, sizeof(buf));
20042 sprintf(buf, "FFScript Version: %d", meta.ffscript_v);
20043 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20044 d->w = zc_max(d->w, t_w);
20045 memset(buf, 0, sizeof(buf));
20046 sprintf(buf, "Script Name: %s", meta.script_name.c_str());
20047 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20048 d->w = zc_max(d->w, t_w);
20049 memset(buf, 0, sizeof(buf));
20050 sprintf(buf, "Author: %s", meta.author.c_str());
20051 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20052 d->w = zc_max(d->w, t_w);
20053 memset(buf, 0, sizeof(buf));
20054 sprintf(buf, "Script Type: %s", get_script_name(meta.script_type).c_str());
20055 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20056 d->w = zc_max(d->w, t_w);
20057 for(auto q = 0; q < 4; ++q)
20058 {
20059 if(!meta.attributes[q].size())
20060 continue;
20061 memset(buf, 0, sizeof(buf));
20062 sprintf(buf, "Attributes[%d]: %s", q, meta.attributes[q].c_str());
20063 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20064 d->w = zc_max(d->w, t_w);
20065 }
20066 for(auto q = 0; q < 8; ++q)
20067 {
20068 if(!meta.attribytes[q].size())
20069 continue;
20070 memset(buf, 0, sizeof(buf));
20071 sprintf(buf, "Attribytes[%d]: %s", q, meta.attribytes[q].c_str());
20072 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20073 d->w = zc_max(d->w, t_w);
20074 }
20075 for(auto q = 0; q < 8; ++q)
20076 {
20077 if(!meta.attrishorts[q].size())
20078 continue;
20079 memset(buf, 0, sizeof(buf));
20080 sprintf(buf, "Attrishorts[%d]: %s", q, meta.attrishorts[q].c_str());
20081 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20082 d->w = zc_max(d->w, t_w);
20083 }
20084 bool indentrun = false;
20085 int32_t run_indent = txtout(NULL, "void run(", 0, 0, false);
20086 std::ostringstream oss;
20087 oss << "void run(";
20088 for(int32_t q = 0; q < 8; ++q)
20089 {
20090 if(!meta.run_idens[q].size() || meta.run_types[q] == ZMETA_NULL_TYPE) continue;
20091 if(q > 0)
20092 oss << ", ";
20093 string type_name = ZScript::getDataTypeName(meta.run_types[q]);
20094 lowerstr(type_name); //all lowercase for this output
20095 if(oss.str().size() > unsigned(indentrun ? 41 : 50))
20096 {
20097 memset(buf, 0, sizeof(buf));
20098 sprintf(buf, "%s", oss.str().c_str());
20099 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
20100 d->w = zc_max(d->w, t_w);
20101 oss.str("");
20102 indentrun = true;
20103 }
20104 oss << type_name.c_str() << " " << meta.run_idens[q];
20105 }
20106 oss << ");";
20107 memset(buf, 0, sizeof(buf));
20108 sprintf(buf, "%s", oss.str().c_str());
20109 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
20110 d->w = zc_max(d->w, t_w);
20111 memset(buf, 0, sizeof(buf));
20112 sprintf(buf, "Compiler Version: %d.%d.%d.%d", meta.compiler_v1, meta.compiler_v2, meta.compiler_v3, meta.compiler_v4);
20113 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20114 d->w = zc_max(d->w, t_w);
20115 memset(buf, 0, sizeof(buf));
20116 sprintf(buf, "Parser-generated: %s", (meta.flags & ZMETA_AUTOGEN)!=0 ? "TRUE" : "FALSE");
20117 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20118 d->w = zc_max(d->w, t_w);
20119 d->h = (++ind) * (text_height(font) + 3) -3;
20120 }
20121 else
20122 {
20123 d->w = txtout(target, "No ZASM metadata found!", d->x, d->y, disabled);
20124 d->h = text_height(font);
20125 }
20126
20127 if(d->dp3) //function trigger
20128 {
20129 typedef void (*funcType)(void);
20130 funcType func=reinterpret_cast<funcType>(d->dp3);
20131 func();
20132 }
20133
20134 font = oldfont;
20135 break;
20136 }
20137 }
20138
20139 return ret;
20140 }
20141
20142 void resize_scriptinfo_dlg();
20143
20144 static DIALOG scriptinfo_dlg[] =
20145 {
20146 // x y w h fg bg key flags d1 d2 dp
20147 { jwin_win_proc, 0, 0, 200, 150, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Metadata", NULL, NULL },
20148 { d_dummy_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, NULL },
20149 { jwin_button_proc, 70, 120, 60, 20, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
20150 { jwin_zmeta_proc, 50, 30, 100, 100, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, (void*)resize_scriptinfo_dlg },
20151
20152 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
20153 };
20154
20155 void resize_scriptinfo_dlg()
20156 {
20157 DIALOG *meta_proc = &scriptinfo_dlg[3], *window = &scriptinfo_dlg[0], *ok_button = &scriptinfo_dlg[2];
20158 int32_t bmargin = 15, hmargins = 30;
20159 jwin_ulalign_dialog(scriptinfo_dlg);
20160 window->w = hmargins*2 + meta_proc->w;
20161 meta_proc->x = hmargins;
20162 window->h = meta_proc->y + meta_proc->h + ok_button->h + bmargin*2;
20163 ok_button->x = (window->w/2)-(ok_button->w/2);
20164 ok_button->y = meta_proc->y + meta_proc->h + bmargin;
20165 jwin_center_dialog(scriptinfo_dlg);
20166 }
20167
20168 void showScriptInfo(zasm_meta const* meta)
20169 {
20170 scriptinfo_dlg[3].dp = (void*)meta;
20171 scriptinfo_dlg[0].dp2 = get_zc_font(font_lfont);
20172 large_dialog(scriptinfo_dlg);
20173 jwin_zmeta_proc(MSG_START,&scriptinfo_dlg[3],0); //Calculate size before calling dialog
20174 jwin_center_dialog(scriptinfo_dlg);
20175 do_zqdialog(scriptinfo_dlg,2);
20176 }
20177
20178 void write_includepaths();
20179 void call_compile_settings();
20180 int32_t onZScriptCompilerSettings()
20181 {
20182 call_compile_settings();
20183 return D_O_K;
20184 }
20185
20186 void doEditZScript()
20187 {
20188 if(do_box_edit(zScript, "ZScript Buffer", false, false))
20189 saved=false;
20190 }
20191
20192 std::string qst_cfg_header_from_path(std::string path);
20193 extern char *filepath;
20194 string get_box_cfg_hdr(int num)
20195 {
20196 if(num)
20197 return "misc";
20198 return qst_cfg_header_from_path(filepath);
20199 }
20200
20201 //{ Start type-specific import dlgs
20202 12 static ListData ffscript_sel_dlg_list(ffscriptlist2, &font);
20203 12 static ListData itemscript_sel_dlg_list(itemscriptlist2, &font);
20204 12 static ListData comboscript_sel_dlg_list(comboscriptlist2, &font);
20205 12 static ListData gscript_sel_dlg_list(gscriptlist2, &font);
20206 static char npcscript_str_buf2[32];
20207 const char *npcscriptlist2(int32_t index, int32_t *list_size)
20208 {
20209 if(index>=0)
20210 {
20211 char buf[20];
20212 bound(index,0,254);
20213
20214 if(npcmap[index].scriptname=="")
20215 strcpy(buf, "<none>");
20216 else
20217 {
20218 strncpy(buf, npcmap[index].scriptname.c_str(), 19);
20219 buf[19]='\0';
20220 }
20221
20222 sprintf(npcscript_str_buf2,"%d: %s",index+1, buf);
20223 return npcscript_str_buf2;
20224 }
20225
20226 *list_size=(NUMSCRIPTGUYS-1);
20227 return NULL;
20228 }
20229 12 static ListData npcscript_sel_dlg_list(npcscriptlist2, &font);
20230 static char lweaponscript_str_buf2[32];
20231 const char *lweaponscriptlist2(int32_t index, int32_t *list_size)
20232 {
20233 if(index>=0)
20234 {
20235 char buf[20];
20236 bound(index,0,254);
20237
20238 if(lwpnmap[index].scriptname=="")
20239 strcpy(buf, "<none>");
20240 else
20241 {
20242 strncpy(buf, lwpnmap[index].scriptname.c_str(), 19);
20243 buf[19]='\0';
20244 }
20245
20246 sprintf(lweaponscript_str_buf2,"%d: %s",index+1, buf);
20247 return lweaponscript_str_buf2;
20248 }
20249
20250 *list_size=(NUMSCRIPTWEAPONS-1);
20251 return NULL;
20252 }
20253 12 static ListData lweaponscript_sel_dlg_list(lweaponscriptlist2, &font);
20254 static char eweaponscript_str_buf2[32];
20255 const char *eweaponscriptlist2(int32_t index, int32_t *list_size)
20256 {
20257 if(index>=0)
20258 {
20259 char buf[20];
20260 bound(index,0,254);
20261
20262 if(ewpnmap[index].scriptname=="")
20263 strcpy(buf, "<none>");
20264 else
20265 {
20266 strncpy(buf, ewpnmap[index].scriptname.c_str(), 19);
20267 buf[19]='\0';
20268 }
20269
20270 sprintf(eweaponscript_str_buf2,"%d: %s",index+1, buf);
20271 return eweaponscript_str_buf2;
20272 }
20273
20274 *list_size=(NUMSCRIPTWEAPONS-1);
20275 return NULL;
20276 }
20277 12 static ListData eweaponscript_sel_dlg_list(eweaponscriptlist2, &font);
20278 static char playerscript_str_buf2[32];
20279 const char *playerscriptlist2(int32_t index, int32_t *list_size)
20280 {
20281 if(index>=0)
20282 {
20283 char buf[20];
20284 bound(index,0,3);
20285
20286 if(playermap[index].scriptname=="")
20287 strcpy(buf, "<none>");
20288 else
20289 {
20290 strncpy(buf, playermap[index].scriptname.c_str(), 19);
20291 buf[19]='\0';
20292 }
20293
20294 if(index==0)
20295 sprintf(playerscript_str_buf2,"Init: %s", buf);
20296
20297 if(index==1)
20298 sprintf(playerscript_str_buf2,"Active: %s", buf);
20299
20300 if(index==2)
20301 sprintf(playerscript_str_buf2,"Death: %s", buf);
20302
20303
20304 //sprintf(playerscript_str_buf2,"%d: %s",index+1, buf);
20305 return playerscript_str_buf2;
20306 }
20307
20308 *list_size=(NUMSCRIPTHERO-1);
20309 return NULL;
20310 }
20311 static char itemspritescript_str_buf2[32];
20312 const char *itemspritescriptlist2(int32_t index, int32_t *list_size)
20313 {
20314 if(index>=0)
20315 {
20316 char buf[20];
20317 bound(index,0,254);
20318
20319 if(itemspritemap[index].scriptname=="")
20320 strcpy(buf, "<none>");
20321 else
20322 {
20323 strncpy(buf, itemspritemap[index].scriptname.c_str(), 19);
20324 buf[19]='\0';
20325 }
20326
20327 sprintf(itemspritescript_str_buf2,"%d: %s",index+1, buf);
20328 return itemspritescript_str_buf2;
20329 }
20330
20331 *list_size=(NUMSCRIPTSITEMSPRITE-1);
20332 return NULL;
20333 }
20334 12 static ListData playerscript_sel_dlg_list(playerscriptlist2, &font);
20335 static char dmapscript_str_buf2[32];
20336 const char *dmapscriptlist2(int32_t index, int32_t *list_size)
20337 {
20338 if(index>=0)
20339 {
20340 char buf[20];
20341 bound(index,0,254);
20342
20343 if(dmapmap[index].scriptname=="")
20344 strcpy(buf, "<none>");
20345 else
20346 {
20347 strncpy(buf, dmapmap[index].scriptname.c_str(), 19);
20348 buf[19]='\0';
20349 }
20350
20351 sprintf(dmapscript_str_buf2,"%d: %s",index+1, buf);
20352 return dmapscript_str_buf2;
20353 }
20354
20355 *list_size=(NUMSCRIPTSDMAP-1);
20356 return NULL;
20357 }
20358 12 static ListData dmapscript_sel_dlg_list(dmapscriptlist2, &font);
20359 12 static ListData itemspritescript_sel_dlg_list(itemspritescriptlist2, &font);
20360 static char screenscript_str_buf2[32];
20361 const char *screenscriptlist2(int32_t index, int32_t *list_size)
20362 {
20363 if(index>=0)
20364 {
20365 char buf[20];
20366 bound(index,0,254);
20367
20368 if(screenmap[index].scriptname=="")
20369 strcpy(buf, "<none>");
20370 else
20371 {
20372 strncpy(buf, screenmap[index].scriptname.c_str(), 19);
20373 buf[19]='\0';
20374 }
20375
20376 sprintf(screenscript_str_buf2,"%d: %s",index+1, buf);
20377 return screenscript_str_buf2;
20378 }
20379
20380 *list_size=(NUMSCRIPTSCREEN-1);
20381 return NULL;
20382 }
20383 12 static ListData screenscript_sel_dlg_list(screenscriptlist2, &font);
20384 //} End type-specific import dlgs
20385
20386 6 void clear_map_states()
20387 {
20388
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = ffcmap.begin();
20389 3072 it != ffcmap.end(); ++it)
20390 {
20391 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20392 3066 }
20393
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(map<int32_t, script_slot_data>::iterator it = globalmap.begin();
20394 54 it != globalmap.end(); ++it)
20395 {
20396 48 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20397 48 }
20398
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemmap.begin();
20399 1536 it != itemmap.end(); ++it)
20400 {
20401 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20402 1530 }
20403
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = npcmap.begin();
20404 1536 it != npcmap.end(); ++it)
20405 {
20406 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20407 1530 }
20408
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = ewpnmap.begin();
20409 1536 it != ewpnmap.end(); ++it)
20410 {
20411 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20412 1530 }
20413
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = lwpnmap.begin();
20414 1536 it != lwpnmap.end(); ++it)
20415 {
20416 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20417 1530 }
20418
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(map<int32_t, script_slot_data>::iterator it = playermap.begin();
20419 30 it != playermap.end(); ++it)
20420 {
20421 24 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20422 24 }
20423
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = dmapmap.begin();
20424 1536 it != dmapmap.end(); ++it)
20425 {
20426 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20427 1530 }
20428
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = screenmap.begin();
20429 1536 it != screenmap.end(); ++it)
20430 {
20431 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20432 1530 }
20433
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(map<int32_t, script_slot_data>::iterator it = itemspritemap.begin();
20434 1536 it != itemspritemap.end(); ++it)
20435 {
20436 1530 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20437 1530 }
20438
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(map<int32_t, script_slot_data>::iterator it = comboscriptmap.begin();
20439 3072 it != comboscriptmap.end(); ++it)
20440 {
20441 3066 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20442 3066 }
20443 6 }
20444
20445 void clearAssignSlotDlg()
20446 {
20447 assignscript_dlg[0].dp2 = get_zc_font(font_lfont);
20448 assignscript_dlg[4].d1 = -1;
20449 assignscript_dlg[5].d1 = -1;
20450 assignscript_dlg[7].d1 = -1;
20451 assignscript_dlg[8].d1 = -1;
20452 assignscript_dlg[10].d1 = -1;
20453 assignscript_dlg[11].d1 = -1;
20454 assignscript_dlg[13].flags = 0;
20455 }
20456
20457 void inc_script_name(string& name)
20458 {
20459 size_t pos = name.find_last_not_of("0123456789");
20460 pos = name.find_first_of("0123456789",pos);
20461 std::ostringstream oss;
20462 if(pos == string::npos)
20463 {
20464 oss << name << 2;
20465 }
20466 else
20467 {
20468 int32_t val = atoi(name.substr(pos).c_str());
20469 oss << name.substr(0,pos) << val+1;
20470 }
20471 name = oss.str();
20472 }
20473
20474 enum script_slot_type
20475 {
20476 type_ffc, type_global, type_itemdata, type_npc, type_lweapon, type_eweapon,
20477 type_hero, type_dmap, type_screen, type_itemsprite, type_combo, type_generic,
20478 type_subscreen, num_types
20479 };
20480 script_slot_type getType(ScriptType type)
20481 {
20482 switch(type)
20483 {
20484 case ScriptType::FFC: return type_ffc;
20485 case ScriptType::Global: return type_global;
20486 case ScriptType::Item: return type_itemdata;
20487 case ScriptType::NPC: return type_npc;
20488 case ScriptType::Lwpn: return type_lweapon;
20489 case ScriptType::Ewpn: return type_eweapon;
20490 case ScriptType::Hero: return type_hero;
20491 case ScriptType::DMap:
20492 case ScriptType::ScriptedActiveSubscreen:
20493 case ScriptType::ScriptedPassiveSubscreen:
20494 case ScriptType::OnMap:
20495 return type_dmap;
20496 case ScriptType::Generic: case ScriptType::GenericFrozen:
20497 return type_generic;
20498 case ScriptType::Screen: return type_screen;
20499 case ScriptType::ItemSprite: return type_itemsprite;
20500 case ScriptType::Combo: return type_combo;
20501 case ScriptType::EngineSubscreen: return type_subscreen;
20502 default: return type_ffc; //Default
20503 }
20504 }
20505 #define SLOTMSGFLAG_MISSING 0x01
20506 #define SLOTMSG_SIZE 512
20507 bool checkSkip(int32_t format, byte flags)
20508 {
20509 switch(format)
20510 {
20511 case SCRIPT_FORMAT_DEFAULT:
20512 return (flags != 0);
20513 case SCRIPT_FORMAT_INVALID:
20514 return ((flags & SLOTMSGFLAG_MISSING)==0);
20515 default: return true;
20516 }
20517 }
20518 void clearAllSlots(int32_t type, byte flags = 0)
20519 {
20520 bound(type,0,num_types-1);
20521 switch(type)
20522 {
20523 case type_ffc:
20524 {
20525 for(int32_t q = 0; q < NUMSCRIPTFFC-1; ++q)
20526 {
20527 if(checkSkip(ffcmap[q].format, flags)) continue;
20528 ffcmap[q].scriptname = "";
20529 ffcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20530 }
20531 break;
20532 }
20533 case type_global:
20534 {
20535 //Start at 1 to not clear Init
20536 for(int32_t q = 1; q < NUMSCRIPTGLOBAL; ++q)
20537 {
20538 if(checkSkip(globalmap[q].format, flags)) continue;
20539 globalmap[q].scriptname = "";
20540 globalmap[q].format = SCRIPT_FORMAT_DEFAULT;
20541 }
20542 break;
20543 }
20544 case type_itemdata:
20545 {
20546 for(int32_t q = 0; q < NUMSCRIPTITEM-1; ++q)
20547 {
20548 if(checkSkip(itemmap[q].format, flags)) continue;
20549 itemmap[q].scriptname = "";
20550 itemmap[q].format = SCRIPT_FORMAT_DEFAULT;
20551 }
20552 break;
20553 }
20554 case type_npc:
20555 {
20556 for(int32_t q = 0; q < NUMSCRIPTGUYS-1; ++q)
20557 {
20558 if(checkSkip(npcmap[q].format, flags)) continue;
20559 npcmap[q].scriptname = "";
20560 npcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20561 }
20562 break;
20563 }
20564 case type_lweapon:
20565 {
20566 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20567 {
20568 if(checkSkip(lwpnmap[q].format, flags)) continue;
20569 lwpnmap[q].scriptname = "";
20570 lwpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20571 }
20572 break;
20573 }
20574 case type_eweapon:
20575 {
20576 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20577 {
20578 if(checkSkip(ewpnmap[q].format, flags)) continue;
20579 ewpnmap[q].scriptname = "";
20580 ewpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20581 }
20582 break;
20583 }
20584 case type_hero:
20585 {
20586 for(int32_t q = 0; q < NUMSCRIPTHERO-1; ++q)
20587 {
20588 if(checkSkip(playermap[q].format, flags)) continue;
20589 playermap[q].scriptname = "";
20590 playermap[q].format = SCRIPT_FORMAT_DEFAULT;
20591 }
20592 break;
20593 }
20594 case type_dmap:
20595 {
20596 for(int32_t q = 0; q < NUMSCRIPTSDMAP-1; ++q)
20597 {
20598 if(checkSkip(dmapmap[q].format, flags)) continue;
20599 dmapmap[q].scriptname = "";
20600 dmapmap[q].format = SCRIPT_FORMAT_DEFAULT;
20601 }
20602 break;
20603 }
20604 case type_screen:
20605 {
20606 for(int32_t q = 0; q < NUMSCRIPTSCREEN-1; ++q)
20607 {
20608 if(checkSkip(screenmap[q].format, flags)) continue;
20609 screenmap[q].scriptname = "";
20610 screenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20611 }
20612 break;
20613 }
20614 case type_itemsprite:
20615 {
20616 for(int32_t q = 0; q < NUMSCRIPTSITEMSPRITE-1; ++q)
20617 {
20618 if(checkSkip(itemspritemap[q].format, flags)) continue;
20619 itemspritemap[q].scriptname = "";
20620 itemspritemap[q].format = SCRIPT_FORMAT_DEFAULT;
20621 }
20622 break;
20623 }
20624 case type_combo:
20625 {
20626 for(int32_t q = 0; q < NUMSCRIPTSCOMBODATA-1; ++q)
20627 {
20628 if(checkSkip(comboscriptmap[q].format, flags)) continue;
20629 comboscriptmap[q].scriptname = "";
20630 comboscriptmap[q].format = SCRIPT_FORMAT_DEFAULT;
20631 }
20632 break;
20633 }
20634 case type_generic:
20635 {
20636 for(int32_t q = 0; q < NUMSCRIPTSGENERIC-1; ++q)
20637 {
20638 if(checkSkip(genericmap[q].format, flags)) continue;
20639 genericmap[q].scriptname = "";
20640 genericmap[q].format = SCRIPT_FORMAT_DEFAULT;
20641 }
20642 break;
20643 }
20644 case type_subscreen:
20645 {
20646 for(int32_t q = 0; q < NUMSCRIPTSSUBSCREEN-1; ++q)
20647 {
20648 if(checkSkip(subscreenmap[q].format, flags)) continue;
20649 subscreenmap[q].scriptname = "";
20650 subscreenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20651 }
20652 break;
20653 }
20654 }
20655 }
20656
20657 static bool doslots_log_output = false, doslots_comment_output = true;
20658 6 void setup_scriptslot_dlg(char* buf, byte flags)
20659 {
20660 //{ Set up the textbox at the bottom, and auto-resize height based on it
20661 6 int32_t prev_height = assignscript_dlg[14].h;
20662 6 memset(buf, 0, SLOTMSG_SIZE);
20663 //
20664 6 strcpy(buf, "Slots with matching names have been updated.\n");
20665
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 3 times.
6 if(flags & SLOTMSGFLAG_MISSING)
20666 3 strcat(buf,"Scripts prefixed with '--' were not found, and will not function.\n");
20667 6 strcat(buf,"Global scripts named 'Init' will be appended to '~Init'");
20668 //
20669
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 SETFLAG(assignscript_dlg[13].flags, D_SELECTED, doslots_log_output);
20670
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 SETFLAG(assignscript_dlg[51].flags, D_SELECTED, doslots_comment_output);
20671 6 assignscript_dlg[14].dp = buf;
20672 6 object_message(&assignscript_dlg[14], MSG_START, 0); //Set the width/height
20673
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(int32_t diff = assignscript_dlg[14].h - prev_height) //resize dlg
20674 {
20675 6 int32_t prev_bottom = assignscript_dlg[14].y + prev_height;
20676
2/2
✓ Branch 0 taken 306 times.
✓ Branch 1 taken 6 times.
312 for(int32_t q = 1; assignscript_dlg[q].proc; ++q)
20677 {
20678
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 300 times.
306 if(q==14) continue; //Don't change self
20679
2/2
✓ Branch 0 taken 276 times.
✓ Branch 1 taken 24 times.
300 if(assignscript_dlg[q].y < prev_bottom) continue; //above proc
20680 24 assignscript_dlg[q].y += diff;
20681 24 }
20682 6 assignscript_dlg[0].h += diff;
20683 6 jwin_center_dialog(assignscript_dlg);
20684 6 }
20685 //}
20686 6 }
20687
20688 std::string global_slotnames[NUMSCRIPTGLOBAL] = {
20689 "Init",
20690 "Active",
20691 "onExit",
20692 "onSaveLoad",
20693 "onLaunch",
20694 "onContGame",
20695 "onF6Menu",
20696 "onSave",
20697 };
20698 std::string player_slotnames[NUMSCRIPTHERO-1] = {
20699 "Init",
20700 "Active",
20701 "onDeath",
20702 "onWin",
20703 };
20704 6 byte reload_scripts(map<string, disassembled_script_data> &scripts)
20705 {
20706 6 byte slotflags = 0;
20707 char temp[100];
20708
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTFFC-1; i++)
20709 {
20710
2/2
✓ Branch 0 taken 2992 times.
✓ Branch 1 taken 74 times.
3066 if(ffcmap[i].isEmpty())
20711 2992 sprintf(temp, "Slot %d:", i+1);
20712 else
20713 {
20714 74 sprintf(temp, "Slot %d:", i+1);
20715
2/2
✓ Branch 0 taken 69 times.
✓ Branch 1 taken 5 times.
74 if(scripts.find(ffcmap[i].scriptname) != scripts.end())
20716 69 ffcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20717 else // Previously loaded script not found
20718 {
20719 5 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
20720 5 slotflags |= SLOTMSGFLAG_MISSING;
20721 }
20722 }
20723 3066 ffcmap[i].slotname = temp;
20724 3066 ffcmap[i].update();
20725 3066 }
20726
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 6 times.
54 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; i++)
20727 {
20728
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 globalmap[i].slotname=fmt::format("{}:",global_slotnames[i]);
20729
2/2
✓ Branch 0 taken 37 times.
✓ Branch 1 taken 11 times.
48 if(!globalmap[i].isEmpty())
20730 {
20731
2/4
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
✗ Branch 3 not taken.
11 if(scripts.find(globalmap[i].scriptname) != scripts.end() || globalmap[i].scriptname == "~Init")
20732 11 globalmap[i].format = SCRIPT_FORMAT_DEFAULT;
20733 else // Unloaded
20734 {
20735 globalmap[i].format = SCRIPT_FORMAT_INVALID;
20736 slotflags |= SLOTMSGFLAG_MISSING;
20737 }
20738 11 }
20739 48 globalmap[i].update();
20740 48 }
20741
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTITEM-1; i++)
20742 {
20743
2/2
✓ Branch 0 taken 1517 times.
✓ Branch 1 taken 13 times.
1530 if(itemmap[i].isEmpty())
20744 1517 sprintf(temp, "Slot %d:", i+1);
20745 else
20746 {
20747 13 sprintf(temp, "Slot %d:", i+1);
20748
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 if(scripts.find(itemmap[i].scriptname) != scripts.end())
20749 13 itemmap[i].format = SCRIPT_FORMAT_DEFAULT;
20750 else // Previously loaded script not found
20751 {
20752 itemmap[i].format = SCRIPT_FORMAT_INVALID;
20753 slotflags |= SLOTMSGFLAG_MISSING;
20754 }
20755 }
20756 1530 itemmap[i].slotname = temp;
20757 1530 itemmap[i].update();
20758 1530 }
20759
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; i++)
20760 {
20761
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(npcmap[i].isEmpty())
20762 1530 sprintf(temp, "Slot %d:", i+1);
20763 else
20764 {
20765 sprintf(temp, "Slot %d:", i+1);
20766 if(scripts.find(npcmap[i].scriptname) != scripts.end())
20767 npcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20768 else // Previously loaded script not found
20769 {
20770 npcmap[i].format = SCRIPT_FORMAT_INVALID;
20771 slotflags |= SLOTMSGFLAG_MISSING;
20772 }
20773 }
20774 1530 npcmap[i].slotname = temp;
20775 1530 npcmap[i].update();
20776 1530 }
20777
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20778 {
20779
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(ewpnmap[i].isEmpty())
20780 1530 sprintf(temp, "Slot %d:", i+1);
20781 else
20782 {
20783 sprintf(temp, "Slot %d:", i+1);
20784 if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
20785 ewpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20786 else // Previously loaded script not found
20787 {
20788 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
20789 slotflags |= SLOTMSGFLAG_MISSING;
20790 }
20791 }
20792 1530 ewpnmap[i].slotname = temp;
20793 1530 ewpnmap[i].update();
20794 1530 }
20795
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20796 {
20797
2/2
✓ Branch 0 taken 1529 times.
✓ Branch 1 taken 1 times.
1530 if(lwpnmap[i].isEmpty())
20798 1529 sprintf(temp, "Slot %d:", i+1);
20799 else
20800 {
20801 1 sprintf(temp, "Slot %d:", i+1);
20802
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
20803 1 lwpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
20804 else // Previously loaded script not found
20805 {
20806 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
20807 slotflags |= SLOTMSGFLAG_MISSING;
20808 }
20809 }
20810 1530 lwpnmap[i].slotname = temp;
20811 1530 lwpnmap[i].update();
20812 1530 }
20813
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(int32_t i = 0; i < NUMSCRIPTHERO-1; i++)
20814 {
20815
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 playermap[i].slotname=fmt::format("{}:",player_slotnames[i]);
20816
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!playermap[i].isEmpty())
20817 {
20818 if(scripts.find(playermap[i].scriptname) != scripts.end())
20819 playermap[i].format = SCRIPT_FORMAT_DEFAULT;
20820 else // Unloaded
20821 {
20822 playermap[i].format = SCRIPT_FORMAT_INVALID;
20823 slotflags |= SLOTMSGFLAG_MISSING;
20824 }
20825 }
20826 24 playermap[i].update();
20827 24 }
20828
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; i++)
20829 {
20830
2/2
✓ Branch 0 taken 1528 times.
✓ Branch 1 taken 2 times.
1530 if(screenmap[i].isEmpty())
20831 1528 sprintf(temp, "Slot %d:", i+1);
20832 else
20833 {
20834 2 sprintf(temp, "Slot %d:", i+1);
20835
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if(scripts.find(screenmap[i].scriptname) != scripts.end())
20836 2 screenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20837 else // Previously loaded script not found
20838 {
20839 screenmap[i].format = SCRIPT_FORMAT_INVALID;
20840 slotflags |= SLOTMSGFLAG_MISSING;
20841 }
20842 }
20843 1530 screenmap[i].slotname = temp;
20844 1530 screenmap[i].update();
20845 1530 }
20846
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; i++)
20847 {
20848
2/2
✓ Branch 0 taken 1525 times.
✓ Branch 1 taken 5 times.
1530 if(dmapmap[i].isEmpty())
20849 1525 sprintf(temp, "Slot %d:", i+1);
20850 else
20851 {
20852 5 sprintf(temp, "Slot %d:", i+1);
20853
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(scripts.find(dmapmap[i].scriptname) != scripts.end())
20854 5 dmapmap[i].format = SCRIPT_FORMAT_DEFAULT;
20855 else // Previously loaded script not found
20856 {
20857 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
20858 slotflags |= SLOTMSGFLAG_MISSING;
20859 }
20860 }
20861 1530 dmapmap[i].slotname = temp;
20862 1530 dmapmap[i].update();
20863 1530 }
20864
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; i++)
20865 {
20866
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(itemspritemap[i].isEmpty())
20867 1530 sprintf(temp, "Slot %d:", i+1);
20868 else
20869 {
20870 sprintf(temp, "Slot %d:", i+1);
20871 if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
20872 itemspritemap[i].format = SCRIPT_FORMAT_DEFAULT;
20873 else // Previously loaded script not found
20874 {
20875 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
20876 slotflags |= SLOTMSGFLAG_MISSING;
20877 }
20878 }
20879 1530 itemspritemap[i].slotname = temp;
20880 1530 itemspritemap[i].update();
20881 1530 }
20882
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; i++)
20883 {
20884
1/2
✓ Branch 0 taken 3066 times.
✗ Branch 1 not taken.
3066 if(comboscriptmap[i].isEmpty())
20885 3066 sprintf(temp, "Slot %d:", i+1);
20886 else
20887 {
20888 sprintf(temp, "Slot %d:", i+1);
20889 if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
20890 comboscriptmap[i].format = SCRIPT_FORMAT_DEFAULT;
20891 else // Previously loaded script not found
20892 {
20893 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
20894 slotflags |= SLOTMSGFLAG_MISSING;
20895 }
20896 }
20897 3066 comboscriptmap[i].slotname = temp;
20898 3066 comboscriptmap[i].update();
20899 3066 }
20900
2/2
✓ Branch 0 taken 3066 times.
✓ Branch 1 taken 6 times.
3072 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; i++)
20901 {
20902
2/2
✓ Branch 0 taken 3051 times.
✓ Branch 1 taken 15 times.
3066 if(genericmap[i].isEmpty())
20903 3051 sprintf(temp, "Slot %d:", i+1);
20904 else
20905 {
20906 15 sprintf(temp, "Slot %d:", i+1);
20907
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 1 times.
15 if(scripts.find(genericmap[i].scriptname) != scripts.end())
20908 14 genericmap[i].format = SCRIPT_FORMAT_DEFAULT;
20909 else // Previously loaded script not found
20910 {
20911 1 genericmap[i].format = SCRIPT_FORMAT_INVALID;
20912 1 slotflags |= SLOTMSGFLAG_MISSING;
20913 }
20914 }
20915 3066 genericmap[i].slotname = temp;
20916 3066 genericmap[i].update();
20917 3066 }
20918
2/2
✓ Branch 0 taken 1530 times.
✓ Branch 1 taken 6 times.
1536 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; i++)
20919 {
20920
1/2
✓ Branch 0 taken 1530 times.
✗ Branch 1 not taken.
1530 if(subscreenmap[i].isEmpty())
20921 1530 sprintf(temp, "Slot %d:", i+1);
20922 else
20923 {
20924 sprintf(temp, "Slot %d:", i+1);
20925 if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
20926 subscreenmap[i].format = SCRIPT_FORMAT_DEFAULT;
20927 else // Previously loaded script not found
20928 {
20929 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
20930 slotflags |= SLOTMSGFLAG_MISSING;
20931 }
20932 }
20933 1530 subscreenmap[i].slotname = temp;
20934 1530 subscreenmap[i].update();
20935 1530 }
20936 6 return slotflags;
20937 }
20938
20939 void doClearSlots(byte* flags);
20940
20941 extern byte compile_success_sample, compile_error_sample,
20942 compile_finish_sample, compile_audio_volume;
20943 static map<string, disassembled_script_data> *doslot_scripts = nullptr;
20944 21510 bool handle_slot(script_slot_data& slotdata, script_data* scriptdata)
20945 {
20946
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 21395 times.
21510 if(slotdata.hasScriptData())
20947 {
20948 115 auto& data = (*doslot_scripts)[slotdata.scriptname];
20949 115 scriptdata->meta = data.meta;
20950 115 scriptdata->pc = data.pc;
20951 115 scriptdata->end_pc = data.end_pc;
20952 115 scriptdata->zasm_script = zasm_scripts[0];
20953 115 }
20954
1/2
✓ Branch 0 taken 21395 times.
✗ Branch 1 not taken.
21395 else if(scriptdata)
20955 {
20956 21395 scriptdata->zasm_script = nullptr;
20957 21395 scriptdata->meta.zero();
20958 21395 scriptdata->pc = 0;
20959 21395 scriptdata->end_pc = 0;
20960 21395 }
20961 21510 return true;
20962 }
20963 78 bool handle_slot_map(map<int32_t, script_slot_data>& mp, int offs, script_data** scriptdata)
20964 {
20965
2/2
✓ Branch 0 taken 21510 times.
✓ Branch 1 taken 78 times.
21588 for(auto it = mp.begin(); it != mp.end(); it++)
20966 {
20967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21510 times.
21510 if(!handle_slot(it->second, scriptdata[it->first + offs]))
20968 return false;
20969 21510 }
20970 78 return true;
20971 78 }
20972
20973 void smart_slot_named(map<string, disassembled_script_data> &scripts,
20974 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
20975 std::string* slotnames, int slotstart, int slotend)
20976 {
20977 for(int q = slotstart; q < slotend; ++q)
20978 {
20979 auto& lval = mp[q];
20980 if(!lval.isEmpty())
20981 continue; //occupied, leave alone
20982 bool done = false;
20983 if(!done) //Check case-sensitive
20984 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20985 {
20986 auto const& rval = scriptnames[rind];
20987 if(rval == "<none>") continue;
20988 if(rval == slotnames[q])
20989 { //Perfect match
20990 lval.updateName(rval);
20991 lval.format = scripts[lval.scriptname].format;
20992 done = true;
20993 break;
20994 }
20995 }
20996 if(!done) //Check case-insensitive
20997 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
20998 {
20999 auto const& rval = scriptnames[rind];
21000 if(rval == "<none>") continue;
21001 string lc_rv = rval, lc_slot = slotnames[q];
21002 lowerstr(lc_rv);
21003 lowerstr(lc_slot);
21004 if(lc_rv == lc_slot)
21005 { //Insensitive match
21006 lval.updateName(rval);
21007 lval.format = scripts[lval.scriptname].format;
21008 break;
21009 }
21010 }
21011 }
21012 }
21013 void smart_slot_type(map<string, disassembled_script_data> &scripts,
21014 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
21015 int slotcount)
21016 {
21017 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
21018 {
21019 auto const& rval = scriptnames[rind];
21020 if(rval == "<none>") continue;
21021 script_slot_data* first_open_slot = nullptr;
21022 bool done = false;
21023 for(int q = 0; q < slotcount; ++q)
21024 {
21025 auto& lval = mp[q];
21026 if(lval.isEmpty())
21027 {
21028 if(!first_open_slot)
21029 first_open_slot = &lval;
21030 }
21031 else if(lval.scriptname == rval)
21032 {
21033 done = true;
21034 break;
21035 }
21036 }
21037 if(!done)
21038 {
21039 if(!first_open_slot)
21040 break; //no slots left to assign to!
21041 first_open_slot->updateName(rval);
21042 first_open_slot->format = scripts[first_open_slot->scriptname].format;
21043 }
21044 }
21045 }
21046
21047 6 bool do_slots(vector<shared_ptr<ZScript::Opcode>> const& zasm,
21048 map<string, disassembled_script_data> &scripts, int assign_mode)
21049 {
21050 6 large_dialog(assignscript_dlg);
21051 6 int32_t ret = 3;
21052 6 char slots_msg[SLOTMSG_SIZE] = {0};
21053 6 byte slotflags = reload_scripts(scripts);
21054 6 setup_scriptslot_dlg(slots_msg, slotflags);
21055 6 bool retval = false;
21056
21057 6 popup_zqdialog_start();
21058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 while(!assign_mode)
21059 {
21060 slotflags = reload_scripts(scripts);
21061 ret = do_zqdialog(assignscript_dlg, ret);
21062
21063 switch(ret)
21064 {
21065 case 0:
21066 case 2:
21067 //Cancel
21068 goto exit_do_slots;
21069
21070 case 3: goto auto_do_slots;
21071
21072 case 6:
21073 //<<, FFC
21074 {
21075 int32_t lind = assignscript_dlg[4].d1;
21076 int32_t rind = assignscript_dlg[5].d1;
21077
21078 if(lind < 0 || rind < 0)
21079 break;
21080
21081 if(asffcscripts[rind] == "<none>")
21082 {
21083 ffcmap[lind].scriptname = "";
21084 ffcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21085 }
21086 else
21087 {
21088 ffcmap[lind].updateName(asffcscripts[rind]);
21089 ffcmap[lind].format = scripts[ffcmap[lind].scriptname].format;
21090 }
21091
21092 break;
21093 }
21094 case 9:
21095 //<<, Global
21096 {
21097 int32_t lind = assignscript_dlg[7].d1;
21098 int32_t rind = assignscript_dlg[8].d1;
21099
21100 if(lind < 0 || rind < 0)
21101 break;
21102
21103 if(lind == 0)
21104 {
21105 jwin_alert("Error","ZScript reserves this slot.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
21106 break;
21107 }
21108
21109 if(asglobalscripts[rind] == "<none>")
21110 {
21111 globalmap[lind].scriptname = "";
21112 globalmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21113 }
21114 else
21115 {
21116 globalmap[lind].updateName(asglobalscripts[rind]);
21117 globalmap[lind].format = scripts[globalmap[lind].scriptname].format;
21118 }
21119
21120 break;
21121 }
21122 case 12:
21123 //<<, ITEM
21124 {
21125 int32_t lind = assignscript_dlg[10].d1;
21126 int32_t rind = assignscript_dlg[11].d1;
21127
21128 if(lind < 0 || rind < 0)
21129 break;
21130
21131 if(asitemscripts[rind] == "<none>")
21132 {
21133 itemmap[lind].scriptname = "";
21134 itemmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21135 }
21136 else
21137 {
21138 itemmap[lind].updateName(asitemscripts[rind]);
21139 itemmap[lind].format = scripts[itemmap[lind].scriptname].format;
21140 }
21141
21142 break;
21143 }
21144 case 20:
21145 //<<, NPC
21146 {
21147 int32_t lind = assignscript_dlg[18].d1;
21148 int32_t rind = assignscript_dlg[19].d1;
21149
21150 if(lind < 0 || rind < 0)
21151 break;
21152
21153 if(asnpcscripts[rind] == "<none>")
21154 {
21155 npcmap[lind].scriptname = "";
21156 npcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21157 }
21158 else
21159 {
21160 npcmap[lind].updateName(asnpcscripts[rind]);
21161 npcmap[lind].format = scripts[npcmap[lind].scriptname].format;
21162 }
21163
21164 break;
21165 }
21166 case 23:
21167 //<<, LWeapon
21168 {
21169 int32_t lind = assignscript_dlg[21].d1;
21170 int32_t rind = assignscript_dlg[22].d1;
21171
21172 if(lind < 0 || rind < 0)
21173 break;
21174
21175 if(aslweaponscripts[rind] == "<none>")
21176 {
21177 lwpnmap[lind].scriptname = "";
21178 lwpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21179 }
21180 else
21181 {
21182 lwpnmap[lind].updateName(aslweaponscripts[rind]);
21183 lwpnmap[lind].format = scripts[lwpnmap[lind].scriptname].format;
21184 }
21185
21186 break;
21187 }
21188 case 26:
21189 //<<, EWeapon
21190 {
21191 int32_t lind = assignscript_dlg[24].d1;
21192 int32_t rind = assignscript_dlg[25].d1;
21193
21194 if(lind < 0 || rind < 0)
21195 break;
21196
21197 if(aseweaponscripts[rind] == "<none>")
21198 {
21199 ewpnmap[lind].scriptname = "";
21200 ewpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21201 }
21202 else
21203 {
21204 ewpnmap[lind].updateName(aseweaponscripts[rind]);
21205 ewpnmap[lind].format = scripts[ewpnmap[lind].scriptname].format;
21206 }
21207
21208 break;
21209 }
21210 case 29:
21211 //<<, Hero
21212 {
21213 int32_t lind = assignscript_dlg[27].d1;
21214 int32_t rind = assignscript_dlg[28].d1;
21215
21216 if(lind < 0 || rind < 0)
21217 break;
21218
21219 if(asplayerscripts[rind] == "<none>")
21220 {
21221 playermap[lind].scriptname = "";
21222 playermap[lind].format = SCRIPT_FORMAT_DEFAULT;
21223 }
21224 else
21225 {
21226 playermap[lind].updateName(asplayerscripts[rind]);
21227 playermap[lind].format = scripts[playermap[lind].scriptname].format;
21228 }
21229
21230 break;
21231 }
21232 case 32:
21233 //<<, Screendata
21234 {
21235 int32_t lind = assignscript_dlg[30].d1;
21236 int32_t rind = assignscript_dlg[31].d1;
21237
21238 if(lind < 0 || rind < 0)
21239 break;
21240
21241 if(asscreenscripts[rind] == "<none>")
21242 {
21243 screenmap[lind].scriptname = "";
21244 screenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21245 }
21246 else
21247 {
21248 screenmap[lind].updateName(asscreenscripts[rind]);
21249 screenmap[lind].format = scripts[screenmap[lind].scriptname].format;
21250 }
21251
21252 break;
21253 }
21254 case 35:
21255 //<<, dmapdata
21256 {
21257 int32_t lind = assignscript_dlg[33].d1;
21258 int32_t rind = assignscript_dlg[34].d1;
21259
21260 if(lind < 0 || rind < 0)
21261 break;
21262
21263 if(asdmapscripts[rind] == "<none>")
21264 {
21265 dmapmap[lind].scriptname = "";
21266 dmapmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21267 }
21268 else
21269 {
21270 dmapmap[lind].updateName(asdmapscripts[rind]);
21271 dmapmap[lind].format = scripts[dmapmap[lind].scriptname].format;
21272 }
21273
21274 break;
21275 }
21276 case 38:
21277 //<<, itemsprite
21278 {
21279 int32_t lind = assignscript_dlg[36].d1;
21280 int32_t rind = assignscript_dlg[37].d1;
21281
21282 if(lind < 0 || rind < 0)
21283 break;
21284
21285 if(asitemspritescripts[rind] == "<none>")
21286 {
21287 itemspritemap[lind].scriptname = "";
21288 itemspritemap[lind].format = SCRIPT_FORMAT_DEFAULT;
21289 }
21290 else
21291 {
21292 itemspritemap[lind].updateName(asitemspritescripts[rind]);
21293 itemspritemap[lind].format = scripts[itemspritemap[lind].scriptname].format;
21294 }
21295
21296 break;
21297 }
21298 case 41:
21299 //<<, comboscript
21300 {
21301 int32_t lind = assignscript_dlg[39].d1;
21302 int32_t rind = assignscript_dlg[40].d1;
21303
21304 if(lind < 0 || rind < 0)
21305 break;
21306
21307 if(ascomboscripts[rind] == "<none>")
21308 {
21309 comboscriptmap[lind].scriptname = "";
21310 comboscriptmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21311 }
21312 else
21313 {
21314 comboscriptmap[lind].updateName(ascomboscripts[rind]);
21315 comboscriptmap[lind].format = scripts[comboscriptmap[lind].scriptname].format;
21316 }
21317
21318 break;
21319 }
21320 case 47:
21321 //<<, generic script
21322 {
21323 int32_t lind = assignscript_dlg[45].d1;
21324 int32_t rind = assignscript_dlg[46].d1;
21325
21326 if(lind < 0 || rind < 0)
21327 break;
21328
21329 if(asgenericscripts[rind] == "<none>")
21330 {
21331 genericmap[lind].scriptname = "";
21332 genericmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21333 }
21334 else
21335 {
21336 genericmap[lind].updateName(asgenericscripts[rind]);
21337 genericmap[lind].format = scripts[genericmap[lind].scriptname].format;
21338 }
21339
21340 break;
21341 }
21342 case 50:
21343 //<<, subscreen script
21344 {
21345 int32_t lind = assignscript_dlg[48].d1;
21346 int32_t rind = assignscript_dlg[49].d1;
21347
21348 if(lind < 0 || rind < 0)
21349 break;
21350
21351 if(assubscreenscripts[rind] == "<none>")
21352 {
21353 subscreenmap[lind].scriptname = "";
21354 subscreenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21355 }
21356 else
21357 {
21358 subscreenmap[lind].updateName(assubscreenscripts[rind]);
21359 subscreenmap[lind].format = scripts[subscreenmap[lind].scriptname].format;
21360 }
21361
21362 break;
21363 }
21364
21365 case 42:
21366 //Script Info, information
21367 {
21368 disassembled_script_data* target = nullptr;
21369 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21370 {
21371 default:
21372 case 0: //FFC
21373 {
21374 int32_t id = assignscript_dlg[4].d1;
21375 if(id > -1 && ffcmap[id].hasScriptData())
21376 {
21377 target = &(scripts[ffcmap[id].scriptname]);
21378 }
21379 break;
21380 }
21381 case 1: //Global
21382 {
21383 int32_t id = assignscript_dlg[7].d1;
21384 if(id > -1 && globalmap[id].hasScriptData())
21385 {
21386 target = &(scripts[globalmap[id].scriptname]);
21387 }
21388 break;
21389 }
21390 case 2: //Item
21391 {
21392 int32_t id = assignscript_dlg[10].d1;
21393 if(id > -1 && itemmap[id].hasScriptData())
21394 {
21395 target = &(scripts[itemmap[id].scriptname]);
21396 }
21397 break;
21398 }
21399 case 3: //npc
21400 {
21401 int32_t id = assignscript_dlg[19].d1;
21402 if(id > -1 && npcmap[id].hasScriptData())
21403 {
21404 target = &(scripts[npcmap[id].scriptname]);
21405 }
21406 break;
21407 }
21408 case 4: //lweapon
21409 {
21410 int32_t id = assignscript_dlg[21].d1;
21411 if(id > -1 && lwpnmap[id].hasScriptData())
21412 {
21413 target = &(scripts[lwpnmap[id].scriptname]);
21414 }
21415 break;
21416 }
21417 case 5: //eweapon
21418 {
21419 int32_t id = assignscript_dlg[24].d1;
21420 if(id > -1 && ewpnmap[id].hasScriptData())
21421 {
21422 target = &(scripts[ewpnmap[id].scriptname]);
21423 }
21424 break;
21425 }
21426 case 6: //hero
21427 {
21428 int32_t id = assignscript_dlg[27].d1;
21429 if(id > -1 && playermap[id].hasScriptData())
21430 {
21431 target = &(scripts[playermap[id].scriptname]);
21432 }
21433 break;
21434 }
21435 case 7: //dmap
21436 {
21437 int32_t id = assignscript_dlg[33].d1;
21438 if(id > -1 && dmapmap[id].hasScriptData())
21439 {
21440 target = &(scripts[dmapmap[id].scriptname]);
21441 }
21442 break;
21443 }
21444 case 8: //screen
21445 {
21446 int32_t id = assignscript_dlg[30].d1;
21447 if(id > -1 && screenmap[id].hasScriptData())
21448 {
21449 target = &(scripts[screenmap[id].scriptname]);
21450 }
21451 break;
21452 }
21453 case 9: //itemsprite
21454 {
21455 int32_t id = assignscript_dlg[36].d1;
21456 if(id > -1 && itemspritemap[id].hasScriptData())
21457 {
21458 target = &(scripts[itemspritemap[id].scriptname]);
21459 }
21460 break;
21461 }
21462 case 10: //combo
21463 {
21464 int32_t id = assignscript_dlg[39].d1;
21465 if(id > -1 && comboscriptmap[id].hasScriptData())
21466 {
21467 target = &(scripts[comboscriptmap[id].scriptname]);
21468 }
21469 break;
21470 }
21471 case 11: //Generic
21472 {
21473 int32_t id = assignscript_dlg[45].d1;
21474 if(id > -1 && genericmap[id].hasScriptData())
21475 {
21476 target = &(scripts[genericmap[id].scriptname]);
21477 }
21478 break;
21479 }
21480 case 12: //Subscreen
21481 {
21482 int32_t id = assignscript_dlg[48].d1;
21483 if(id > -1 && subscreenmap[id].hasScriptData())
21484 {
21485 target = &(scripts[subscreenmap[id].scriptname]);
21486 }
21487 break;
21488 }
21489 }
21490 if(target)
21491 showScriptInfo(&target->meta);
21492 break;
21493 }
21494
21495 case 43:
21496 //Script Info, information
21497 {
21498 disassembled_script_data* target = NULL;
21499 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21500 {
21501 default:
21502 case 0: //FFC
21503 {
21504 int32_t id = assignscript_dlg[5].d1;
21505 if(id < 0 || asffcscripts[id] == "<none>" || asffcscripts[id].at(0) == '-') break;
21506 target = &(scripts[asffcscripts[id]]);
21507 break;
21508 }
21509 case 1: //Global
21510 {
21511 int32_t id = assignscript_dlg[8].d1;
21512 if(id < 0 || asglobalscripts[id] == "<none>" || asglobalscripts[id].at(0) == '-') break;
21513 target = &(scripts[asglobalscripts[id]]);
21514 break;
21515 }
21516 case 2: //Item
21517 {
21518 int32_t id = assignscript_dlg[11].d1;
21519 if(id < 0 || asitemscripts[id] == "<none>" || asitemscripts[id].at(0) == '-') break;
21520 target = &(scripts[asitemscripts[id]]);
21521 break;
21522 }
21523 case 3: //npc
21524 {
21525 int32_t id = assignscript_dlg[20].d1;
21526 if(id < 0 || asnpcscripts[id] == "<none>" || asnpcscripts[id].at(0) == '-') break;
21527 target = &(scripts[asnpcscripts[id]]);
21528 break;
21529 }
21530 case 4: //lweapon
21531 {
21532 int32_t id = assignscript_dlg[22].d1;
21533 if(id < 0 || aslweaponscripts[id] == "<none>" || aslweaponscripts[id].at(0) == '-') break;
21534 target = &(scripts[aslweaponscripts[id]]);
21535 break;
21536 }
21537 case 5: //eweapon
21538 {
21539 int32_t id = assignscript_dlg[25].d1;
21540 if(id < 0 || aseweaponscripts[id] == "<none>" || aseweaponscripts[id].at(0) == '-') break;
21541 target = &(scripts[aseweaponscripts[id]]);
21542 break;
21543 }
21544 case 6: //hero
21545 {
21546 int32_t id = assignscript_dlg[28].d1;
21547 if(id < 0 || asplayerscripts[id] == "<none>" || asplayerscripts[id].at(0) == '-') break;
21548 target = &(scripts[asplayerscripts[id]]);
21549 break;
21550 }
21551 case 7: //dmap
21552 {
21553 int32_t id = assignscript_dlg[34].d1;
21554 if(id < 0 || asdmapscripts[id] == "<none>" || asdmapscripts[id].at(0) == '-') break;
21555 target = &(scripts[asdmapscripts[id]]);
21556 break;
21557 }
21558 case 8: //screen
21559 {
21560 int32_t id = assignscript_dlg[31].d1;
21561 if(id < 0 || asscreenscripts[id] == "<none>" || asscreenscripts[id].at(0) == '-') break;
21562 target = &(scripts[asscreenscripts[id]]);
21563 break;
21564 }
21565 case 9: //itemsprite
21566 {
21567 int32_t id = assignscript_dlg[37].d1;
21568 if(id < 0 || asitemspritescripts[id] == "<none>" || asitemspritescripts[id].at(0) == '-') break;
21569 target = &(scripts[asitemspritescripts[id]]);
21570 break;
21571 }
21572 case 10: //combo
21573 {
21574 int32_t id = assignscript_dlg[40].d1;
21575 if(id < 0 || ascomboscripts[id] == "<none>" || ascomboscripts[id].at(0) == '-') break;
21576 target = &(scripts[ascomboscripts[id]]);
21577 break;
21578 }
21579 case 11: //generic
21580 {
21581 int32_t id = assignscript_dlg[46].d1;
21582 if(id < 0 || asgenericscripts[id] == "<none>" || asgenericscripts[id].at(0) == '-') break;
21583 target = &(scripts[asgenericscripts[id]]);
21584 break;
21585 }
21586 case 12: //subscreen
21587 {
21588 int32_t id = assignscript_dlg[49].d1;
21589 if(id < 0 || assubscreenscripts[id] == "<none>" || assubscreenscripts[id].at(0) == '-') break;
21590 target = &(scripts[assubscreenscripts[id]]);
21591 break;
21592 }
21593 }
21594 if(target)
21595 showScriptInfo(&target->meta);
21596 break;
21597 }
21598
21599 case 44:
21600 //Clear, clear slots of current type- after a confirmation.
21601 {
21602 doClearSlots(&slotflags);
21603 break;
21604 }
21605 }
21606 }
21607
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(assign_mode == 2) //Smart Assign
21608 {
21609 //For global/hero scripts, match slot names if unoccupied
21610 smart_slot_named(scripts, asglobalscripts, globalmap, global_slotnames, 1, NUMSCRIPTGLOBAL);
21611 smart_slot_named(scripts, asplayerscripts, playermap, player_slotnames, 0, NUMSCRIPTHERO-1);
21612 //For other scripts, assign all un-assigned scripts
21613 smart_slot_type(scripts, asffcscripts, ffcmap, NUMSCRIPTFFC-1);
21614 smart_slot_type(scripts, asitemscripts, itemmap, NUMSCRIPTITEM-1);
21615 smart_slot_type(scripts, asnpcscripts, npcmap, NUMSCRIPTGUYS-1);
21616 smart_slot_type(scripts, aslweaponscripts, lwpnmap, NUMSCRIPTWEAPONS-1);
21617 smart_slot_type(scripts, aseweaponscripts, ewpnmap, NUMSCRIPTWEAPONS-1);
21618 smart_slot_type(scripts, asscreenscripts, screenmap, NUMSCRIPTSCREEN-1);
21619 smart_slot_type(scripts, asdmapscripts, dmapmap, NUMSCRIPTSDMAP-1);
21620 smart_slot_type(scripts, asitemspritescripts, itemspritemap, NUMSCRIPTSITEMSPRITE-1);
21621 smart_slot_type(scripts, ascomboscripts, comboscriptmap, NUMSCRIPTSCOMBODATA-1);
21622 smart_slot_type(scripts, asgenericscripts, genericmap, NUMSCRIPTSGENERIC-1);
21623 smart_slot_type(scripts, assubscreenscripts, subscreenmap, NUMSCRIPTSSUBSCREEN-1);
21624 }
21625 auto_do_slots:
21626 6 doslots_log_output = (assignscript_dlg[13].flags == D_SELECTED);
21627 6 doslots_comment_output = (assignscript_dlg[51].flags == D_SELECTED);
21628 6 doslot_scripts = &scripts;
21629 //OK
21630 {
21631
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(doslots_log_output)
21632 {
21633 string outstr;
21634 write_script(zasm, outstr, doslots_comment_output, doslot_scripts);
21635 safe_al_trace(outstr);
21636 }
21637 6 auto start_assign_time = std::chrono::steady_clock::now();
21638 6 string zasm_str;
21639
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 write_script(zasm, zasm_str, false, nullptr);
21640
21641 6 std::vector<ffscript> zasm;
21642
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(parse_script_string(zasm, zasm_str, false))
21643 goto exit_do_slots;
21644
21645 6 zasm_scripts.clear();
21646
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 zasm_scripts.emplace_back(std::make_shared<zasm_script>(std::move(zasm)));
21647
21648
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ffcmap, 1, ffscripts))
21649 goto exit_do_slots;
21650
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(globalmap, 0, globalscripts))
21651 goto exit_do_slots;
21652
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemmap, 1, itemscripts))
21653 goto exit_do_slots;
21654
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(npcmap, 1, guyscripts))
21655 goto exit_do_slots;
21656
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(lwpnmap, 1, lwpnscripts))
21657 goto exit_do_slots;
21658
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(ewpnmap, 1, ewpnscripts))
21659 goto exit_do_slots;
21660
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(playermap, 1, playerscripts))
21661 goto exit_do_slots;
21662
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(dmapmap, 1, dmapscripts))
21663 goto exit_do_slots;
21664
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(screenmap, 1, screenscripts))
21665 goto exit_do_slots;
21666
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(itemspritemap, 1, itemspritescripts))
21667 goto exit_do_slots;
21668
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(comboscriptmap, 1, comboscripts))
21669 goto exit_do_slots;
21670
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(genericmap, 1, genericscripts))
21671 goto exit_do_slots;
21672
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if(!handle_slot_map(subscreenmap, 1, subscreenscripts))
21673 goto exit_do_slots;
21674
21675 6 auto end_assign_time = std::chrono::steady_clock::now();
21676
3/6
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
6 int compile_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign_time - start_assign_time).count();
21677
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 al_trace("Assign Slots took %d ms\n", compile_time_ms);
21678 6 char buf[256] = {0};
21679 12 sprintf(buf, "ZScripts successfully loaded into script slots"
21680 6 "\nAssign Slots took %d ms", compile_time_ms);
21681
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_finish_sample = vbound(zc_get_config("Compiler","compile_finish_sample",20),0,255);
21682
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 compile_audio_volume = vbound(zc_get_config("Compiler","compile_audio_volume",200),0,255);
21683
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21684 {
21685
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(sfxdat)
21686 sfx_voice[compile_finish_sample]=allocate_voice((SAMPLE*)sfxdata[compile_finish_sample].dat);
21687
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 else sfx_voice[compile_finish_sample]=allocate_voice(&customsfxdata[compile_finish_sample]);
21688
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_set_volume(sfx_voice[compile_finish_sample], compile_audio_volume);
21689
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 voice_start(sfx_voice[compile_finish_sample]);
21690 6 }
21691
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!assign_mode)
21692 InfoDialog("Slots Assigned",buf).show();
21693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if ( compile_finish_sample > 0 )
21694 {
21695
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(sfx_voice[compile_finish_sample]!=-1)
21696 {
21697
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 deallocate_voice(sfx_voice[compile_finish_sample]);
21698 6 sfx_voice[compile_finish_sample]=-1;
21699 6 }
21700 6 }
21701
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biffs_list();
21702
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 build_biitems_list();
21703 6 retval = true;
21704 6 goto exit_do_slots;
21705
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 }
21706 exit_do_slots:
21707 6 doslot_scripts = nullptr;
21708 6 popup_zqdialog_end();
21709 6 return retval;
21710 }
21711
21712 static char slottype_str_buf[32];
21713
21714 const char *slottype_list(int32_t index, int32_t *list_size)
21715 {
21716 if(index >= 0)
21717 {
21718 bound(index,0,num_types-1);
21719
21720 switch(index)
21721 {
21722 case type_ffc:
21723 strcpy(slottype_str_buf, "FFC");
21724 break;
21725 case type_global:
21726 strcpy(slottype_str_buf, "Global");
21727 break;
21728 case type_itemdata:
21729 strcpy(slottype_str_buf, "Item");
21730 break;
21731 case type_npc:
21732 strcpy(slottype_str_buf, "NPC");
21733 break;
21734 case type_lweapon:
21735 strcpy(slottype_str_buf, "LWeapon");
21736 break;
21737 case type_eweapon:
21738 strcpy(slottype_str_buf, "EWeapon");
21739 break;
21740 case type_hero:
21741 strcpy(slottype_str_buf, "Hero");
21742 break;
21743 case type_dmap:
21744 strcpy(slottype_str_buf, "DMap");
21745 break;
21746 case type_screen:
21747 strcpy(slottype_str_buf, "Screen");
21748 break;
21749 case type_itemsprite:
21750 strcpy(slottype_str_buf, "ItemSprite");
21751 break;
21752 case type_combo:
21753 strcpy(slottype_str_buf, "Combo");
21754 break;
21755 case type_generic:
21756 strcpy(slottype_str_buf, "Generic");
21757 break;
21758 case type_subscreen:
21759 strcpy(slottype_str_buf, "Subscreen");
21760 break;
21761 }
21762
21763 return slottype_str_buf;
21764 }
21765 *list_size = 11;
21766 return NULL;
21767 }
21768 12 static ListData slottype_sel_list(slottype_list, &font);
21769
21770 static DIALOG clearslots_dlg[] =
21771 {
21772 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear Slots", NULL, NULL },
21773 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21774 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21775 12 { jwin_droplist_proc, 50, 28+16, 70, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21776 12 { jwin_radio_proc, 40, 34+00, 81, 9, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Clear Script Type:", NULL, NULL },
21777 12 { jwin_radio_proc, 40, 34+32, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Missing (--) Slots", NULL, NULL },
21778 12 { jwin_radio_proc, 40, 34+80, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear All", NULL, NULL },
21779 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
21780 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21781 };
21782
21783 void doClearSlots(byte* flags)
21784 {
21785 //{ Setup
21786 clearslots_dlg[0].dp2=get_zc_font(font_lfont);
21787 clearslots_dlg[3].d1 = get_selected_tab((TABPANEL*)assignscript_dlg[1].dp); //Default to current tab's type
21788 clearslots_dlg[4].flags |= D_SELECTED;
21789 clearslots_dlg[5].flags &= ~D_SELECTED;
21790 clearslots_dlg[6].flags &= ~D_SELECTED;
21791 if(((*flags) & SLOTMSGFLAG_MISSING) == 0)
21792 clearslots_dlg[5].flags |= D_DISABLED;
21793 else
21794 clearslots_dlg[5].flags &= ~D_DISABLED;
21795 //}
21796
21797 large_dialog(clearslots_dlg);
21798
21799 if(do_zqdialog(clearslots_dlg,2)==1)
21800 {
21801 int32_t q = 3;
21802 while((clearslots_dlg[++q].flags & D_SELECTED) == 0);
21803 switch(q)
21804 {
21805 case 4: //Clear type
21806 {
21807 clearAllSlots(clearslots_dlg[3].d1);
21808 break;
21809 }
21810 case 5: //Clear Missing
21811 {
21812 for(int32_t q = 0; q <= 10; ++q)
21813 clearAllSlots(q,SLOTMSGFLAG_MISSING);
21814 break;
21815 }
21816 case 6: //Clear ALL
21817 {
21818 for(int32_t q = 0; q <= 10; ++q)
21819 clearAllSlots(q);
21820 break;
21821 }
21822 }
21823 }
21824 }
21825
21826 static DIALOG exportzasm_dlg[] =
21827 {
21828 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Export ZASM", NULL, NULL },
21829 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21830 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21831 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21832 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21833 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21834 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21835 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21836 };
21837
21838 static DIALOG importzasm_dlg[] =
21839 {
21840 12 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import ZASM", NULL, NULL },
21841 12 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
21842 12 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
21843 12 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
21844 12 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
21845 // 5
21846 12 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
21847 12 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
21848 12 { jwin_text_proc, 50, 28+72, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Name:", NULL, NULL },
21849 12 { jwin_edit_proc, 50, 28+80, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 19, 0, NULL, NULL, NULL },
21850
21851 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
21852 };
21853 extern ListData itemscript_list;
21854 extern ListData itemspritescript_list;
21855 extern ListData lweaponscript_list;
21856 extern ListData npcscript_list;
21857 extern ListData eweaponscript_list;
21858 extern ListData comboscript_list;
21859
21860 8 void center_zscript_dialogs()
21861 {
21862 8 jwin_center_dialog(exportzasm_dlg);
21863 8 jwin_center_dialog(importzasm_dlg);
21864 8 jwin_center_dialog(clearslots_dlg);
21865 8 }
21866
21867 // array of voices, one for each sfx sample in the data file
21868 // 0+ = voice #
21869 // -1 = voice not allocated
21870 int32_t sfx_voice[WAV_COUNT];
21871
21872 void Z_init_sound()
21873 {
21874 for(int32_t i=0; i<WAV_COUNT; i++)
21875 sfx_voice[i]=-1;
21876
21877 // master_volume(digi_volume,midi_volume);
21878 }
21879
21880 // returns number of voices currently allocated
21881 int32_t sfx_count()
21882 {
21883 int32_t c=0;
21884
21885 for(int32_t i=0; i<WAV_COUNT; i++)
21886 if(sfx_voice[i]!=-1)
21887 ++c;
21888
21889 return c;
21890 }
21891
21892 // clean up finished samples
21893 void sfx_cleanup()
21894 {
21895 for(int32_t i=0; i<WAV_COUNT; i++)
21896 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
21897 {
21898 deallocate_voice(sfx_voice[i]);
21899 sfx_voice[i]=-1;
21900 }
21901 }
21902
21903 // allocates a voice for the sample "wav_index" (index into zelda.dat)
21904 // if a voice is already allocated (and/or playing), then it just returns true
21905 // Returns true: voice is allocated
21906 // false: unsuccessful
21907 SAMPLE templist[WAV_COUNT];
21908
21909 bool sfx_init(int32_t index)
21910 {
21911 // check index
21912 if(index<1 || index>=WAV_COUNT)
21913 return false;
21914
21915 if(sfx_voice[index]==-1)
21916 {
21917 sfx_voice[index]=allocate_voice(&templist[index]);
21918 }
21919
21920 return sfx_voice[index] != -1;
21921 }
21922
21923 // plays an sfx sample
21924 void sfx(int32_t index,int32_t pan,bool loop,bool restart,int32_t vol,int32_t freq)
21925 {
21926 if(!sfx_init(index))
21927 return;
21928
21929 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21930 voice_set_pan(sfx_voice[index],pan);
21931
21932 int32_t pos = voice_get_position(sfx_voice[index]);
21933
21934 if(restart) voice_set_position(sfx_voice[index],0);
21935
21936 if(pos<=0)
21937 voice_start(sfx_voice[index]);
21938 }
21939
21940 // start it (in loop mode) if it's not already playing,
21941 // otherwise just leave it in its current position
21942 void cont_sfx(int32_t index)
21943 {
21944 if(!sfx_init(index))
21945 return;
21946
21947 if(voice_get_position(sfx_voice[index])<=0)
21948 {
21949 voice_set_position(sfx_voice[index],0);
21950 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
21951 voice_start(sfx_voice[index]);
21952 }
21953 }
21954
21955 // adjust parameters while playing
21956 void adjust_sfx(int32_t index,int32_t pan,bool loop)
21957 {
21958 if(index<0 || index>=WAV_COUNT || sfx_voice[index]==-1)
21959 return;
21960
21961 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
21962 voice_set_pan(sfx_voice[index],pan);
21963 }
21964
21965 // pauses a voice
21966 void pause_sfx(int32_t index)
21967 {
21968 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21969 voice_stop(sfx_voice[index]);
21970 }
21971
21972 // resumes a voice
21973 void resume_sfx(int32_t index)
21974 {
21975 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
21976 voice_start(sfx_voice[index]);
21977 }
21978
21979 // pauses all active voices
21980 void pause_all_sfx()
21981 {
21982 for(int32_t i=0; i<WAV_COUNT; i++)
21983 if(sfx_voice[i]!=-1)
21984 voice_stop(sfx_voice[i]);
21985 }
21986
21987 // resumes all paused voices
21988 void resume_all_sfx()
21989 {
21990 for(int32_t i=0; i<WAV_COUNT; i++)
21991 if(sfx_voice[i]!=-1)
21992 voice_start(sfx_voice[i]);
21993 }
21994
21995 // stops an sfx and deallocates the voice
21996 void stop_sfx(int32_t index)
21997 {
21998 if(index<0 || index>=WAV_COUNT)
21999 return;
22000
22001 if(sfx_voice[index]!=-1)
22002 {
22003 deallocate_voice(sfx_voice[index]);
22004 sfx_voice[index]=-1;
22005 }
22006 }
22007
22008 void kill_sfx()
22009 {
22010 for(int32_t i=0; i<WAV_COUNT; i++)
22011 if(sfx_voice[i]!=-1)
22012 {
22013 deallocate_voice(sfx_voice[i]);
22014 sfx_voice[i]=-1;
22015 }
22016 }
22017
22018 int32_t pan(int32_t x)
22019 {
22020 return 128;
22021 /*switch(pan_style)
22022 {
22023 case 0: return 128;
22024 case 1: return vbound((x>>1)+68,0,255);
22025 case 2: return vbound(((x*3)>>2)+36,0,255);
22026 }
22027 return vbound(x,0,255);*/
22028 }
22029
22030
22031 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2)
22032 {
22033 sfx1->bits = sfx2->bits;
22034 sfx1->stereo = sfx2->stereo;
22035 sfx1->freq = sfx2->freq;
22036 sfx1->priority = sfx2->priority;
22037 sfx1->len = sfx2->len;
22038 sfx1->loop_start = sfx2->loop_start;
22039 sfx1->loop_end = sfx2->loop_end;
22040 sfx1->param = sfx2->param;
22041
22042 if(sfx1->data != NULL)
22043 {
22044 free(sfx1->data);
22045 }
22046
22047 if(sfx2->data == NULL)
22048 sfx1->data = NULL;
22049 else
22050 {
22051 // When quests are saved and loaded, data is written in words.
22052 // If the last byte is dropped, it'll cause the sound to end with
22053 // a click. It could simply be extended and padded with 0, but
22054 // that causes compatibility issues... So we'll cut off
22055 // the last byte and decrease the length.
22056
22057 int32_t len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
22058
22059 while(len%sizeof(word))
22060 {
22061 // sizeof(word) should be 2, so this doesn't really need
22062 // to be a loop, but what the heck.
22063 sfx1->len--;
22064 len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
22065 }
22066
22067 sfx1->data = malloc(len);
22068 memcpy(sfx1->data, sfx2->data, len);
22069 }
22070 }
22071
22072 bool confirmBox(const char *m1, const char *m2, const char *m3)
22073 {
22074 if(!m3)
22075 {
22076 if(!m2) m2 = "Are you sure?";
22077 else m3 = "Are you sure?";
22078 }
22079 return jwin_alert("Confirmation", m1, m2, m3, "Yes", "No", 'y', 'n', get_zc_font(font_lfont)) == 1;
22080 }
22081
22082 int32_t onSelectSFX()
22083 {
22084 SFXListerDialog(0).show();
22085 refresh(rMAP+rCOMBOS);
22086 return D_O_K;
22087 }
22088
22089 bool saveWAV(int32_t slot, const char *filename)
22090 {
22091 if (slot < 1 || slot >= 511 )
22092 return false;
22093
22094 if (customsfxdata[slot].data == NULL)
22095 return false;
22096
22097 std::ofstream ofs(filename, std::ios::binary);
22098 if (!ofs)
22099 return false;
22100 ofs.write("RIFF",4);
22101 uint32_t samplerate = customsfxdata[slot].freq;
22102 uint16_t channels = customsfxdata[slot].stereo ? 2 : 1;
22103 uint32_t datalen = customsfxdata[slot].len*channels*customsfxdata[slot].bits / 8;
22104 uint32_t size = 36 + datalen;
22105 ofs.write((char *)&size, 4);
22106 ofs.write("WAVE", 4);
22107 ofs.write("fmt ", 4);
22108 uint32_t fmtlen = 16;
22109 ofs.write((char *)&fmtlen, 4);
22110 uint16_t type = 1;
22111 ofs.write((char *)&type, 2);
22112 ofs.write((char *)&channels, 2);
22113 ofs.write((char *)&samplerate, 4);
22114 uint32_t bytespersec = samplerate*channels*customsfxdata[slot].bits / 8;
22115 ofs.write((char *)&bytespersec, 4);
22116 uint16_t blockalign = channels*customsfxdata[slot].bits / 8;
22117 ofs.write((char *)&blockalign, 2);
22118 uint16_t bitspersample = customsfxdata[slot].bits;
22119 ofs.write((char *)&bitspersample, 2);
22120 ofs.write("data", 4);
22121 ofs.write((char *)&datalen, 4);
22122 if (bitspersample == 8)
22123 {
22124 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
22125 {
22126 char data = ((char *)customsfxdata[slot].data)[i];
22127 data ^= 0x80;
22128 ofs.write(&data, 1);
22129 }
22130 }
22131 else if (bitspersample == 16)
22132 {
22133 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
22134 {
22135 uint16_t data = ((uint16_t *)customsfxdata[slot].data)[i];
22136 data ^= 0x8000;
22137 ofs.write((char *)&data, 2);
22138 }
22139 }
22140 else
22141 return false;
22142 return !!ofs;
22143 }
22144
22145 int32_t onEditSFX(int32_t index)
22146 {
22147 call_sfxdata_dialog(index);
22148 return D_O_K;
22149 }
22150
22151 int32_t onMapStyles()
22152 {
22153 call_mapstyles_dialog();
22154 return D_O_K;
22155 }
22156
22157 int32_t d_misccolors_old_proc(int32_t msg,DIALOG *d,int32_t c)
22158 {
22159 //these are here to bypass compiler warnings about unused arguments
22160 c=c;
22161
22162 if(msg==MSG_DRAW)
22163 {
22164 textout_ex(screen,font,"0123456789ABCDEF",d->x+8,d->y,d->fg,d->bg);
22165 textout_ex(screen,font,"0",d->x,d->y+8,d->fg,d->bg);
22166 textout_ex(screen,font,"1",d->x,d->y+16,d->fg,d->bg);
22167 textout_ex(screen,font,"5",d->x,d->y+24,d->fg,d->bg);
22168
22169 for(int32_t i=0; i<32; i++)
22170 {
22171 int32_t px2 = d->x+((i&15)<<3)+8;
22172 int32_t py2 = d->y+((i>>4)<<3)+8;
22173 rectfill(screen,px2,py2,px2+7,py2+7,i);
22174 }
22175
22176 for(int32_t i=0; i<16; i++)
22177 {
22178 int32_t px2 = d->x+(i<<3)+8;
22179 rectfill(screen,px2,d->y+24,px2+7,d->y+31,i+80);
22180 }
22181 }
22182
22183 return D_O_K;
22184 }
22185
22186 int32_t hexclicked=-1;
22187
22188 int32_t d_misccolors_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
22189 {
22190 switch(msg)
22191 {
22192 case MSG_GOTFOCUS:
22193 hexclicked=((int32_t)(size_t)(d->dp3))+20;
22194 break;
22195
22196 case MSG_LOSTFOCUS:
22197 hexclicked=-1;
22198 break;
22199 }
22200
22201 return d_hexedit_proc(msg,d,c);
22202 }
22203
22204
22205 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c);
22206
22207 static int32_t misccolor1_list[] =
22208 {
22209 // dialog control number
22210 4, 5, 6, 7, 8, 20, 21, 22, 23, 24, 36, 37, 38, 39, 40, -1
22211 };
22212
22213 static int32_t misccolor2_list[] =
22214 {
22215 // dialog control number
22216 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 41, 42, 43, 44, 45, -1
22217 };
22218
22219 static int32_t misccolor3_list[] =
22220 {
22221 // dialog control number
22222 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 46, 47, 48, 49, 50, -1
22223 };
22224
22225 static int32_t misccolor4_list[] =
22226 {
22227 19, 35, 51, 54, 55, 56, -1
22228 };
22229
22230 static TABPANEL misccolor_tabs[] =
22231 {
22232 // (text)
22233 { (char *)"1", D_SELECTED, misccolor1_list, 0, NULL },
22234 { (char *)"2", 0, misccolor2_list, 0, NULL },
22235 { (char *)"3", 0, misccolor3_list, 0, NULL },
22236 { (char *)"4", 0, misccolor4_list, 0, NULL },
22237 { NULL, 0, NULL, 0, NULL }
22238 };
22239
22240 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c);
22241
22242 static DIALOG misccolors_dlg[] =
22243 {
22244 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
22245 12 { jwin_win_proc, 2, 21, 316, 197-23, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Misc Colors", NULL, NULL },
22246 // { jwin_frame_proc, 98-84+1+2, 52+8-6+4, 132, 100, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
22247 12 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22248 12 { d_misccolors_proc, 92-84+1+2, 44+8-6+4, 128+8, 96+8, vc(9), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
22249 //3
22250 12 { d_misccolors_tab_proc, 150+14-2+10-15, 60-14, 150-10+15, 144-20-10, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) misccolor_tabs, NULL, (void *)misccolors_dlg },
22251 //4
22252 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Text:", NULL, NULL },
22253 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Caption:", NULL, NULL },
22254 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Overworld Minmap:", NULL, NULL },
22255 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Background:", NULL, NULL },
22256 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 1:", NULL, NULL },
22257 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 2:", NULL, NULL },
22258 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Dark:", NULL, NULL },
22259 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Goal:", NULL, NULL },
22260 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Light):", NULL, NULL },
22261 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Dark):", NULL, NULL },
22262 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Background:", NULL, NULL },
22263 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Shadow:", NULL, NULL },
22264 12 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Triforce Frame:", NULL, NULL },
22265 12 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Background:", NULL, NULL },
22266 12 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Foreground:", NULL, NULL },
22267 12 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hero's Position:", NULL, NULL },
22268
22269 //20
22270 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)0, },
22271 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)1, },
22272 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)2, },
22273 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)3, },
22274 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)4, },
22275 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)5, },
22276 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)6, },
22277 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)7, },
22278 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)8, },
22279 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)9, },
22280 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)10, },
22281 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)11, },
22282 12 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)12, },
22283 12 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)13, },
22284 12 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)14, },
22285 12 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)15, },
22286
22287 //36
22288 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22289 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22290 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22291 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22292 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22293 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22294 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22295 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22296 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22297 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22298 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22299 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22300 12 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22301 12 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22302 12 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22303 12 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22304
22305 //52
22306 12 { jwin_button_proc, 90, 190-20, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22307 12 { jwin_button_proc, 170, 190-20, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22308 12 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Message Text:", NULL, NULL },
22309 12 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)35, },
22310 12 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22311 12 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22312 };
22313
22314 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c)
22315 {
22316
22317 switch(msg)
22318 {
22319 case MSG_WANTFOCUS:
22320 return D_WANTFOCUS;
22321 break;
22322 }
22323
22324 return jwin_tab_proc(msg,d,c);
22325 }
22326
22327
22328 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c)
22329 {
22330 //these are here to bypass compiler warnings about unused arguments
22331 c=c;
22332 int32_t mul=12;
22333
22334 switch(msg)
22335 {
22336 case MSG_CLICK:
22337 if(hexclicked!=-1)
22338 {
22339 int32_t color_col=vbound(((gui_mouse_x()-d->x-8)/mul),0,15);
22340 int32_t color_row=vbound(((gui_mouse_y()-d->y-10)/mul),0,11);
22341 sprintf((char*)misccolors_dlg[hexclicked].dp,"%X%X",color_row,color_col);
22342 object_message(misccolors_dlg+hexclicked,MSG_DRAW,0);
22343 }
22344
22345 break;
22346
22347 case MSG_DRAW:
22348 for(int32_t i=0; i<10; i++)
22349 {
22350 textprintf_centre_ex(screen,font,d->x+8+4+(i*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22351 }
22352
22353 for(int32_t i=0; i<6; i++)
22354 {
22355 textprintf_centre_ex(screen,font,d->x+8+4+((10+i)*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22356 }
22357
22358 for(int32_t i=0; i<10; i++)
22359 {
22360 textprintf_right_ex(screen,font,d->x+6,d->y+(i*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22361 }
22362
22363 for(int32_t i=0; i<2; i++)
22364 {
22365 textprintf_right_ex(screen,font,d->x+6,d->y+((i+10)*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22366 }
22367
22368 jwin_draw_frame(screen,d->x+6,d->y+8,int32_t(132*1.5)-2,int32_t(100*1.5)-2,FR_DEEP);
22369
22370 for(int32_t i=0; i<192; i++)
22371 {
22372 int32_t px2 = d->x+int32_t(((i&15)<<3)*1.5)+8;
22373 int32_t py2 = d->y+int32_t(((i>>4)<<3)*1.5)+8+2;
22374 rectfill(screen,px2,py2,px2+(mul-1),py2+(mul-1),i);
22375 }
22376
22377 break;
22378 }
22379
22380 return D_O_K;
22381 }
22382
22383
22384 int32_t onMiscColors()
22385 {
22386 char buf[17][3];
22387 byte *si = &(QMisc.colors.text);
22388 misccolors_dlg[0].dp2=get_zc_font(font_lfont);
22389
22390 for(int32_t i=0; i<16; i++)
22391 {
22392 sprintf(buf[i],"%02X",*(si++));
22393 sprintf(buf[16], "%02X", QMisc.colors.msgtext);
22394 misccolors_dlg[i+20].dp = buf[i];
22395 misccolors_dlg[55].dp = buf[16];
22396 }
22397
22398 large_dialog(misccolors_dlg);
22399
22400 if(do_zqdialog(misccolors_dlg,0)==52)
22401 {
22402 saved=false;
22403 si = &(QMisc.colors.text);
22404
22405 for(int32_t i=0; i<16; i++)
22406 {
22407 *si = zc_xtoi(buf[i]);
22408 ++si;
22409 }
22410
22411 QMisc.colors.msgtext = zc_xtoi(buf[16]);
22412 }
22413
22414 return D_O_K;
22415 }
22416
22417 // **** Palette cycling ****
22418
22419 static int32_t palclk[3];
22420 static int32_t palpos[3];
22421
22422 32 void reset_pal_cycling()
22423 {
22424
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 32 times.
128 for(int32_t i=0; i<3; i++)
22425 96 palclk[i]=palpos[i]=0;
22426 32 }
22427
22428 void cycle_palette()
22429 {
22430 if(!get_qr(qr_FADE))
22431 return;
22432
22433 int32_t level = Map.CurrScr()->color;
22434 bool refreshpal = false;
22435
22436 for(int32_t i=0; i<3; i++)
22437 {
22438 palcycle c = QMisc.cycles[level][i];
22439
22440 if(c.count&0xF0)
22441 {
22442 if(++palclk[i] >= c.speed)
22443 {
22444 palclk[i]=0;
22445
22446 if(++palpos[i] >= (c.count>>4))
22447 palpos[i]=0;
22448
22449 byte *si = colordata + CSET(level*pdLEVEL+poFADE1+1+palpos[i])*3;
22450
22451 si += (c.first&15)*3;
22452
22453 for(int32_t col=c.first&15; col<=(c.count&15); col++)
22454 {
22455 RAMpal[CSET(c.first>>4)+col] = _RGB(si);
22456 si+=3;
22457 }
22458
22459 refreshpal = true;
22460 }
22461 }
22462 }
22463
22464 if(refreshpal)
22465 {
22466 rebuild_trans_table();
22467 zc_set_palette_range(RAMpal,0,192,false);
22468 }
22469 }
22470
22471
22472 void doHelp()
22473 {
22474 do_box_edit(helpstr, "ZQuest Help", true, true);
22475 }
22476
22477 int32_t onHelp()
22478 {
22479 restore_mouse();
22480 doHelp();
22481 return D_O_K;
22482 }
22483
22484 void doZstringshelp()
22485 {
22486 do_box_edit(zstringshelpstr, "ZStrings Help", true, true);
22487 }
22488
22489 int32_t onZstringshelp()
22490 {
22491 restore_mouse();
22492 doZstringshelp();
22493 return D_O_K;
22494 }
22495
22496 static DIALOG layerdata_dlg[] =
22497 {
22498 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22499 { jwin_win_proc, 16-12, 20+32, 288+1+24, 200+1-32-16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Layer Data", NULL, NULL },
22500 { jwin_button_proc, 170, 180, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22501 { jwin_button_proc, 90, 180, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22502 // 3
22503 { jwin_rtext_proc, 72, 88, 40, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Map:", NULL, NULL },
22504 { jwin_rtext_proc, 72, 88+18, 48, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
22505 { jwin_rtext_proc, 72, 88+36, 56, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Transparent:", NULL, NULL },
22506 { jwin_ctext_proc, 89, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
22507 { jwin_ctext_proc, 89+40, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
22508 { jwin_ctext_proc, 89+80, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
22509 { jwin_ctext_proc, 89+120, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
22510 { jwin_ctext_proc, 89+160, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
22511 { jwin_ctext_proc, 89+200, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
22512
22513 //12
22514 { jwin_edit_proc, 76, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22515 { d_hexedit_proc, 76, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22516 { jwin_check_proc, 76, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22517
22518 { jwin_edit_proc, 76+40, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22519 { d_hexedit_proc, 76+40, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22520 { jwin_check_proc, 76+40, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22521
22522 { jwin_edit_proc, 76+80, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22523 { d_hexedit_proc, 76+80, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22524 { jwin_check_proc, 76+80, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22525
22526 { jwin_edit_proc, 76+120, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22527 { d_hexedit_proc, 76+120, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22528 { jwin_check_proc, 76+120, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22529
22530 { jwin_edit_proc, 76+160, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22531 { d_hexedit_proc, 76+160, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22532 { jwin_check_proc, 76+160, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22533
22534 { jwin_edit_proc, 76+200, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22535 { d_hexedit_proc, 76+200, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
22536 { jwin_check_proc, 76+200, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
22537
22538 //30
22539 { jwin_button_proc, 76, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22540 { jwin_button_proc, 76+40, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22541 { jwin_button_proc, 76+80, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22542 { jwin_button_proc, 76+120, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22543 { jwin_button_proc, 76+160, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22544 { jwin_button_proc, 76+200, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
22545
22546 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22547 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22548
22549 };
22550
22551 int32_t edit_layers(mapscr* tempscr)
22552 {
22553 char buf[6][2][8];
22554 layerdata_dlg[0].dp2 = get_zc_font(font_lfont);
22555
22556 for(int32_t x=0; x<6; x++)
22557 {
22558 sprintf(buf[x][0],"%d",tempscr->layermap[x]);
22559 sprintf(buf[x][1],"%02X",tempscr->layerscreen[x]);
22560 }
22561
22562 for(int32_t x=0; x<6; x++)
22563 {
22564 for(int32_t y=0; y<2; y++)
22565 {
22566 layerdata_dlg[(x*3)+y+12].dp = buf[x][y];
22567 }
22568 }
22569
22570 for(int32_t x=0; x<6; x++)
22571 {
22572 layerdata_dlg[(x*3)+2+12].flags = (tempscr->layeropacity[x]<255) ? D_SELECTED : 0;
22573 }
22574
22575 large_dialog(layerdata_dlg);
22576
22577 int32_t ret=do_zqdialog(layerdata_dlg,0);
22578
22579 if(ret>=2)
22580 {
22581 for(int32_t x=0; x<6; x++)
22582 {
22583
22584 tempscr->layermap[x]=atoi(buf[x][0]);
22585
22586 if(tempscr->layermap[x]>map_count)
22587 {
22588 tempscr->layermap[x]=0;
22589 }
22590
22591 tempscr->layerscreen[x]=zc_xtoi(buf[x][1]);
22592
22593 if(zc_xtoi(buf[x][1])>=MAPSCRS)
22594 {
22595 tempscr->layerscreen[x]=0;
22596 }
22597
22598 // tempscr->layeropacity[x]=layerdata_dlg[(x*9)+8+19].flags & D_SELECTED ? 128:255;
22599 tempscr->layeropacity[x]=layerdata_dlg[(x*3)+2+12].flags & D_SELECTED ? 128:255;
22600 }
22601
22602 // } else if (ret>72&&ret<79) {
22603 // return (ret-72);
22604 }
22605
22606 return ret;
22607 }
22608
22609 static DIALOG autolayer_dlg[] =
22610 {
22611 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22612 { jwin_win_proc, 64, 32+48, 192+1, 184+1-64, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Autolayer Setup", NULL, NULL },
22613 { jwin_text_proc, 76, 56+48, 136, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map for layer ?: ", NULL, NULL },
22614 { jwin_edit_proc, 212, 56+48, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
22615 { jwin_check_proc, 76, 56+18+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Screens", NULL, NULL },
22616 { jwin_button_proc, 90, 188-12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22617
22618 //5
22619 { jwin_button_proc, 170, 188-12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22620 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
22621 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22622 { jwin_check_proc, 76, 56+28+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Layers", NULL, NULL },
22623 { jwin_check_proc, 76, 56+38+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Overwrite Layers", NULL, NULL },
22624
22625 //10
22626 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22627 };
22628 enum
22629 {
22630 autolyr_blankscreens,
22631 autolyr_blanklayers,
22632 autolyr_any
22633 };
22634 void autolayer(mapscr* tempscr, int32_t layer, int32_t al[6][3])
22635 {
22636 char tbuf[80],mlayer[80];
22637 autolayer_dlg[0].dp2=get_zc_font(font_lfont);
22638 sprintf(tbuf, "Map for layer %d: ", layer+1);
22639 autolayer_dlg[1].dp=tbuf;
22640 sprintf(mlayer, "%d", tempscr->layermap[layer]);
22641 autolayer_dlg[2].dp=mlayer;
22642
22643 large_dialog(autolayer_dlg);
22644 int ret, sel = 8, fl = autolyr_blanklayers;
22645 bool running = true;
22646 do
22647 {
22648 SETFLAG(autolayer_dlg[3].flags, D_SELECTED, sel==3);
22649 SETFLAG(autolayer_dlg[8].flags, D_SELECTED, sel==8);
22650 SETFLAG(autolayer_dlg[9].flags, D_SELECTED, sel==9);
22651 switch(ret=do_zqdialog(autolayer_dlg,0))
22652 {
22653 case 4: //OK
22654 {
22655 int32_t lmap=vbound(atoi(mlayer),0,Map.getMapCount());
22656 al[layer][0]=lmap;
22657 tempscr->layermap[layer]=lmap;
22658 tempscr->layerscreen[layer]=Map.getCurrScr();
22659 al[layer][1]=fl;
22660 al[layer][2]=1;
22661 running = false;
22662 break;
22663 }
22664 case 0: case 5: //cancel
22665 running = false;
22666 break;
22667 case 3:
22668 sel = ret;
22669 fl = autolyr_blankscreens;
22670 break;
22671 case 8:
22672 sel = ret;
22673 fl = autolyr_blanklayers;
22674 break;
22675 case 9:
22676 sel = ret;
22677 fl = autolyr_any;
22678 break;
22679 }
22680 }
22681 while(ret != 0 && ret != 4 && ret != 5);
22682 }
22683
22684 int32_t onLayers()
22685 {
22686 mapscr tempscr=*Map.CurrScr();
22687 int32_t al[6][3]; //autolayer[layer][0=map, 1=autolyr_ type, 2=bool go]
22688
22689 for(int32_t i=0; i<6; i++)
22690 {
22691 al[i][0]=tempscr.layermap[i];
22692 al[i][1]=0;
22693 al[i][2]=0;
22694 }
22695
22696 int32_t ret;
22697
22698 do
22699 {
22700 ret=edit_layers(&tempscr);
22701
22702 if(ret>2) //autolayer button
22703 {
22704 autolayer(&tempscr, ret-30, al);
22705 }
22706 }
22707 while(ret>2); //autolayer button
22708
22709 if(ret==2) //OK
22710 {
22711 saved=false;
22712 TheMaps[Map.getCurrMap()*MAPSCRS+Map.getCurrScr()]=tempscr;
22713
22714 for(int32_t i=0; i<6; i++)
22715 {
22716 int32_t tm=tempscr.layermap[i]-1;
22717 int32_t ts=tempscr.layerscreen[i];
22718
22719 if(al[i][2])
22720 {
22721 map_autolayers[Map.getCurrMap()*6+i] = al[i][0];
22722 for(int32_t j=0; j<128; j++)
22723 {
22724 auto& curmapscr = TheMaps[Map.getCurrMap()*MAPSCRS+j];
22725 if(al[i][1] == autolyr_blankscreens && (curmapscr.valid&mVALID))
22726 continue;
22727 else if(al[i][1] == autolyr_blanklayers && curmapscr.layermap[i])
22728 continue;
22729
22730 curmapscr.layermap[i]=al[i][0];
22731 curmapscr.layerscreen[i]=al[i][0]?j:0;
22732 }
22733 }
22734 }
22735 }
22736
22737 // Check that the working layer wasn't just disabled
22738 if(CurrentLayer>0 && tempscr.layermap[CurrentLayer-1]==0)
22739 CurrentLayer=0;
22740
22741 return D_O_K;
22742 }
22743
22744
22745 char *itoa(int32_t i)
22746 {
22747 static char itoaret[500];
22748 sprintf(itoaret, "%d", i);
22749 return itoaret;
22750 }
22751
22752 20 void fps_callback()
22753 {
22754 20 lastfps=framecnt;
22755 20 framecnt=0;
22756 20 }
22757
22758 END_OF_FUNCTION(fps_callback)
22759
22760 //uint32_t col_diff[3*128];
22761 /*
22762 void bestfit_init(void)
22763 {
22764 int32_t i;
22765
22766 for (i=1; i<64; i++)
22767
22768 {
22769 int32_t k = i * i;
22770 col_diff[0 +i] = col_diff[0 +128-i] = k * (59 * 59);
22771 col_diff[128+i] = col_diff[128+128-i] = k * (30 * 30);
22772 col_diff[256+i] = col_diff[256+128-i] = k * (11 * 11);
22773 }
22774 }
22775 */
22776 20 void create_rgb_table2(RGB_MAP *table, AL_CONST PALETTE pal_8bit, void (*callback)(int32_t pos))
22777 {
22778 #define UNUSED 65535
22779 #define LAST 65532
22780
22781 // Allegro has been modified to use an 8 bit palette, but this method and RGB_MAP still use 6 bit.
22782 PALETTE pal;
22783
2/2
✓ Branch 0 taken 5120 times.
✓ Branch 1 taken 20 times.
5140 for (int i = 0; i < 256; i++)
22784 {
22785 5120 pal[i] = pal_8bit[i];
22786 5120 pal[i].r /= 4;
22787 5120 pal[i].g /= 4;
22788 5120 pal[i].b /= 4;
22789 5120 }
22790
22791 /* macro add adds to single linked list */
22792 #define add(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22793 (first != LAST ? (next[last] = (i)) : (first = (i))), \
22794 (last = (i))) : 0)
22795
22796 /* same but w/o checking for first element */
22797 #define add1(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
22798 next[last] = (i), \
22799 (last = (i))) : 0)
22800 /* calculates distance between two colors */
22801 #define dist(a1, a2, a3, b1, b2, b3) \
22802 (col_diff[ ((a2) - (b2)) & 0x7F] + \
22803 (col_diff + 128)[((a1) - (b1)) & 0x7F] + \
22804 (col_diff + 256)[((a3) - (b3)) & 0x7F])
22805
22806 /* converts r,g,b to position in array and back */
22807 #define pos(r, g, b) \
22808 (((r) / 2) * 32 * 32 + ((g) / 2) * 32 + ((b) / 2))
22809
22810 #define depos(pal, r, g, b) \
22811 ((b) = ((pal) & 31) * 2, \
22812 (g) = (((pal) >> 5) & 31) * 2, \
22813 (r) = (((pal) >> 10) & 31) * 2)
22814
22815 /* is current color better than pal1? */
22816 #define better(r1, g1, b1, pal1) \
22817 (((int32_t)dist((r1), (g1), (b1), \
22818 (pal1).r, (pal1).g, (pal1).b)) > (int32_t)dist2)
22819
22820 /* checking of position */
22821 #define dopos(rp, gp, bp, ts) \
22822 if ((rp > -1 || r > 0) && (rp < 1 || r < 61) && \
22823 (gp > -1 || g > 0) && (gp < 1 || g < 61) && \
22824 (bp > -1 || b > 0) && (bp < 1 || b < 61)) \
22825 { \
22826 i = first + rp * 32 * 32 + gp * 32 + bp; \
22827 if (!data[i]) \
22828 { \
22829 data[i] = val; \
22830 add1(i); \
22831 } \
22832 else if ((ts) && (data[i] != val)) \
22833 { \
22834 dist2 = (rp ? (col_diff+128)[(r+2*rp-pal[val].r) & 0x7F] : r2) + \
22835 (gp ? (col_diff )[(g+2*gp-pal[val].g) & 0x7F] : g2) + \
22836 (bp ? (col_diff+256)[(b+2*bp-pal[val].b) & 0x7F] : b2); \
22837 if (better((r+2*rp), (g+2*gp), (b+2*bp), pal[data[i]])) \
22838 { \
22839 data[i] = val; \
22840 add1(i); \
22841 } \
22842 } \
22843 }
22844
22845 int32_t i, curr, r, g, b, val, dist2;
22846 uint32_t r2, g2, b2;
22847 uint16_t next[32*32*32];
22848 uint8_t *data;
22849 20 int32_t first = LAST;
22850 20 int32_t last = LAST;
22851 20 int32_t count = 0;
22852 20 int32_t cbcount = 0;
22853
22854 #define AVERAGE_COUNT 18000
22855
22856
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 9 times.
20 if(col_diff[1] == 0)
22857 11 bestfit_init();
22858
22859 20 memset(next, 255, sizeof(next));
22860 20 memset(table->data, 0, sizeof(char)*32*32*32);
22861
22862
22863 20 data = (uint8_t *)table->data;
22864
22865 /* add starting seeds for floodfill */
22866
2/2
✓ Branch 0 taken 5100 times.
✓ Branch 1 taken 20 times.
5120 for(i=1; i<PAL_SIZE; i++)
22867 {
22868 5100 curr = pos(pal[i].r, pal[i].g, pal[i].b);
22869
22870
2/2
✓ Branch 0 taken 3845 times.
✓ Branch 1 taken 1255 times.
5100 if(next[curr] == UNUSED)
22871 {
22872 1255 data[curr] = i;
22873
3/4
✓ Branch 0 taken 1255 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1235 times.
✓ Branch 3 taken 20 times.
1255 add(curr);
22874 1255 }
22875 5100 }
22876
22877 /* main floodfill: two versions of loop for faster growing in blue axis */
22878 // while (first != LAST) {
22879
2/2
✓ Branch 0 taken 429183 times.
✓ Branch 1 taken 20 times.
429203 while(first < LAST)
22880 {
22881 429183 depos(first, r, g, b);
22882
22883 /* calculate distance of current color */
22884 429183 val = data[first];
22885 429183 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22886 429183 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22887 429183 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22888
22889 /* try to grow to all directions */
22890 #ifdef _MSC_VER
22891 #pragma warning(disable:4127)
22892 #endif
22893
11/12
✓ Branch 0 taken 14101 times.
✓ Branch 1 taken 415082 times.
✓ Branch 2 taken 398571 times.
✓ Branch 3 taken 16511 times.
✓ Branch 4 taken 16511 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 332919 times.
✓ Branch 7 taken 65652 times.
✓ Branch 8 taken 18284 times.
✓ Branch 9 taken 47368 times.
✓ Branch 10 taken 29323 times.
✓ Branch 11 taken 18045 times.
827754 dopos(0, 0, 1, 1);
22894
11/12
✓ Branch 0 taken 12699 times.
✓ Branch 1 taken 416484 times.
✓ Branch 2 taken 401923 times.
✓ Branch 3 taken 14561 times.
✓ Branch 4 taken 14561 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 349828 times.
✓ Branch 7 taken 52095 times.
✓ Branch 8 taken 20564 times.
✓ Branch 9 taken 31531 times.
✓ Branch 10 taken 20781 times.
✓ Branch 11 taken 10750 times.
831106 dopos(0, 0,-1, 1);
22895
11/12
✓ Branch 0 taken 13697 times.
✓ Branch 1 taken 415486 times.
✓ Branch 2 taken 404706 times.
✓ Branch 3 taken 10780 times.
✓ Branch 4 taken 10780 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 330555 times.
✓ Branch 7 taken 74151 times.
✓ Branch 8 taken 47933 times.
✓ Branch 9 taken 26218 times.
✓ Branch 10 taken 16472 times.
✓ Branch 11 taken 9746 times.
833889 dopos(1, 0, 0, 1);
22896
11/12
✓ Branch 0 taken 13827 times.
✓ Branch 1 taken 415356 times.
✓ Branch 2 taken 403888 times.
✓ Branch 3 taken 11468 times.
✓ Branch 4 taken 11468 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 333000 times.
✓ Branch 7 taken 70888 times.
✓ Branch 8 taken 46836 times.
✓ Branch 9 taken 24052 times.
✓ Branch 10 taken 15162 times.
✓ Branch 11 taken 8890 times.
833071 dopos(-1, 0, 0, 1);
22897
11/12
✓ Branch 0 taken 13907 times.
✓ Branch 1 taken 415276 times.
✓ Branch 2 taken 372893 times.
✓ Branch 3 taken 42383 times.
✓ Branch 4 taken 42383 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 276647 times.
✓ Branch 7 taken 96246 times.
✓ Branch 8 taken 79329 times.
✓ Branch 9 taken 16917 times.
✓ Branch 10 taken 10951 times.
✓ Branch 11 taken 5966 times.
802076 dopos(0, 1, 0, 1);
22898
11/12
✓ Branch 0 taken 12535 times.
✓ Branch 1 taken 416648 times.
✓ Branch 2 taken 380106 times.
✓ Branch 3 taken 36542 times.
✓ Branch 4 taken 36542 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 284832 times.
✓ Branch 7 taken 95274 times.
✓ Branch 8 taken 81293 times.
✓ Branch 9 taken 13981 times.
✓ Branch 10 taken 8680 times.
✓ Branch 11 taken 5301 times.
809289 dopos(0,-1, 0, 1);
22899 #ifdef _MSC_VER
22900 #pragma warning(default:4127)
22901 #endif
22902
22903 /* faster growing of blue direction */
22904
4/4
✓ Branch 0 taken 416484 times.
✓ Branch 1 taken 12699 times.
✓ Branch 2 taken 20564 times.
✓ Branch 3 taken 395920 times.
429183 if((b > 0) && (data[first-1] == val))
22905 {
22906 395920 b -= 2;
22907 395920 first--;
22908 395920 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22909
22910 #ifdef _MSC_VER
22911 #pragma warning(disable:4127)
22912 #endif
22913
5/6
✓ Branch 0 taken 12878 times.
✓ Branch 1 taken 383042 times.
✓ Branch 2 taken 348408 times.
✓ Branch 3 taken 34634 times.
✓ Branch 4 taken 34634 times.
✗ Branch 5 not taken.
744328 dopos(-1, 0, 0, 0);
22914
5/6
✓ Branch 0 taken 12724 times.
✓ Branch 1 taken 383196 times.
✓ Branch 2 taken 348427 times.
✓ Branch 3 taken 34769 times.
✓ Branch 4 taken 34769 times.
✗ Branch 5 not taken.
744347 dopos(1, 0, 0, 0);
22915
5/6
✓ Branch 0 taken 11649 times.
✓ Branch 1 taken 384271 times.
✓ Branch 2 taken 338859 times.
✓ Branch 3 taken 45412 times.
✓ Branch 4 taken 45412 times.
✗ Branch 5 not taken.
734779 dopos(0,-1, 0, 0);
22916
5/6
✓ Branch 0 taken 12957 times.
✓ Branch 1 taken 382963 times.
✓ Branch 2 taken 320826 times.
✓ Branch 3 taken 62137 times.
✓ Branch 4 taken 62137 times.
✗ Branch 5 not taken.
716746 dopos(0, 1, 0, 0);
22917 #ifdef _MSC_VER
22918 #pragma warning(default:4127)
22919 #endif
22920
22921 395920 first++;
22922 395920 }
22923
22924 /* get next from list */
22925 429183 i = first;
22926 429183 first = next[first];
22927 429183 next[i] = UNUSED;
22928
22929 /* second version of loop */
22930 // if (first != LAST) {
22931
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 429172 times.
429183 if(first < LAST)
22932 {
22933
22934 429172 depos(first, r, g, b);
22935
22936 429172 val = data[first];
22937 429172 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
22938 429172 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
22939 429172 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
22940
22941 #ifdef _MSC_VER
22942 #pragma warning(disable:4127)
22943 #endif
22944
11/12
✓ Branch 0 taken 13641 times.
✓ Branch 1 taken 415531 times.
✓ Branch 2 taken 396272 times.
✓ Branch 3 taken 19259 times.
✓ Branch 4 taken 19259 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 330690 times.
✓ Branch 7 taken 65582 times.
✓ Branch 8 taken 18256 times.
✓ Branch 9 taken 47326 times.
✓ Branch 10 taken 29220 times.
✓ Branch 11 taken 18106 times.
825444 dopos(0, 0, 1, 1);
22945
11/12
✓ Branch 0 taken 12635 times.
✓ Branch 1 taken 416537 times.
✓ Branch 2 taken 404145 times.
✓ Branch 3 taken 12392 times.
✓ Branch 4 taken 12392 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 351839 times.
✓ Branch 7 taken 52306 times.
✓ Branch 8 taken 20992 times.
✓ Branch 9 taken 31314 times.
✓ Branch 10 taken 20771 times.
✓ Branch 11 taken 10543 times.
833317 dopos(0, 0,-1, 1);
22946
11/12
✓ Branch 0 taken 13884 times.
✓ Branch 1 taken 415288 times.
✓ Branch 2 taken 404087 times.
✓ Branch 3 taken 11201 times.
✓ Branch 4 taken 11201 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 329794 times.
✓ Branch 7 taken 74293 times.
✓ Branch 8 taken 48225 times.
✓ Branch 9 taken 26068 times.
✓ Branch 10 taken 16394 times.
✓ Branch 11 taken 9674 times.
833259 dopos(1, 0, 0, 1);
22947
11/12
✓ Branch 0 taken 13673 times.
✓ Branch 1 taken 415499 times.
✓ Branch 2 taken 404148 times.
✓ Branch 3 taken 11351 times.
✓ Branch 4 taken 11351 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 333182 times.
✓ Branch 7 taken 70966 times.
✓ Branch 8 taken 47175 times.
✓ Branch 9 taken 23791 times.
✓ Branch 10 taken 15386 times.
✓ Branch 11 taken 8405 times.
833320 dopos(-1, 0, 0, 1);
22948
11/12
✓ Branch 0 taken 13833 times.
✓ Branch 1 taken 415339 times.
✓ Branch 2 taken 373807 times.
✓ Branch 3 taken 41532 times.
✓ Branch 4 taken 41532 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 278007 times.
✓ Branch 7 taken 95800 times.
✓ Branch 8 taken 79051 times.
✓ Branch 9 taken 16749 times.
✓ Branch 10 taken 10979 times.
✓ Branch 11 taken 5770 times.
802979 dopos(0, 1, 0, 1);
22949
11/12
✓ Branch 0 taken 12418 times.
✓ Branch 1 taken 416754 times.
✓ Branch 2 taken 380954 times.
✓ Branch 3 taken 35800 times.
✓ Branch 4 taken 35800 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 285632 times.
✓ Branch 7 taken 95322 times.
✓ Branch 8 taken 81439 times.
✓ Branch 9 taken 13883 times.
✓ Branch 10 taken 8876 times.
✓ Branch 11 taken 5007 times.
810126 dopos(0,-1, 0, 1);
22950 #ifdef _MSC_VER
22951 #pragma warning(default:4127)
22952 #endif
22953
22954
4/4
✓ Branch 0 taken 415531 times.
✓ Branch 1 taken 13641 times.
✓ Branch 2 taken 18256 times.
✓ Branch 3 taken 397275 times.
429172 if((b < 61) && (data[first + 1] == val))
22955 {
22956 397275 b += 2;
22957 397275 first++;
22958 397275 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7f];
22959 #ifdef _MSC_VER
22960 #pragma warning(disable:4127)
22961 #endif
22962
5/6
✓ Branch 0 taken 12768 times.
✓ Branch 1 taken 384507 times.
✓ Branch 2 taken 344848 times.
✓ Branch 3 taken 39659 times.
✓ Branch 4 taken 39659 times.
✗ Branch 5 not taken.
742123 dopos(-1, 0, 0, 0);
22963
5/6
✓ Branch 0 taken 12844 times.
✓ Branch 1 taken 384431 times.
✓ Branch 2 taken 337589 times.
✓ Branch 3 taken 46842 times.
✓ Branch 4 taken 46842 times.
✗ Branch 5 not taken.
734864 dopos(1, 0, 0, 0);
22964
5/6
✓ Branch 0 taken 11483 times.
✓ Branch 1 taken 385792 times.
✓ Branch 2 taken 322053 times.
✓ Branch 3 taken 63739 times.
✓ Branch 4 taken 63739 times.
✗ Branch 5 not taken.
719328 dopos(0,-1, 0, 0);
22965
5/6
✓ Branch 0 taken 12999 times.
✓ Branch 1 taken 384276 times.
✓ Branch 2 taken 321143 times.
✓ Branch 3 taken 63133 times.
✓ Branch 4 taken 63133 times.
✗ Branch 5 not taken.
718418 dopos(0, 1, 0, 0);
22966 #ifdef _MSC_VER
22967 #pragma warning(default:4127)
22968 #endif
22969
22970 397275 first--;
22971 397275 }
22972
22973 429172 i = first;
22974 429172 first = next[first];
22975 429172 next[i] = UNUSED;
22976 429172 }
22977
22978 429183 count++;
22979
22980
2/2
✓ Branch 0 taken 424043 times.
✓ Branch 1 taken 5140 times.
429183 if(count == (cbcount+1)*AVERAGE_COUNT/256)
22981 {
22982
2/2
✓ Branch 0 taken 20 times.
✓ Branch 1 taken 5120 times.
5140 if(cbcount < 256)
22983 {
22984
1/2
✓ Branch 0 taken 5120 times.
✗ Branch 1 not taken.
5120 if(callback)
22985 callback(cbcount);
22986
22987 5120 cbcount++;
22988 5120 }
22989 5140 }
22990
22991 }
22992
22993 /* only the transparent (pink) color can be mapped to index 0 */
22994
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
20 if((pal[0].r == 63) && (pal[0].g == 0) && (pal[0].b == 63))
22995 table->data[31][0][31] = 0;
22996
22997
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if(callback)
22998 while(cbcount < 256)
22999 callback(cbcount++);
23000 20 }
23001
23002 20 void rebuild_trans_table()
23003 {
23004 20 create_rgb_table2(&zq_rgb_table, RAMpal, NULL);
23005 20 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
23006 20 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
23007
23008
2/2
✓ Branch 0 taken 5120 times.
✓ Branch 1 taken 20 times.
5140 for(int32_t q=0; q<PAL_SIZE; q++)
23009 {
23010 5120 trans_table2.data[0][q] = q;
23011 5120 trans_table2.data[q][q] = q;
23012 5120 }
23013 20 }
23014
23015 int32_t isFullScreen()
23016 {
23017 return !is_windowed_mode();
23018 }
23019
23020 void hit_close_button()
23021 {
23022 close_button_quit=true;
23023 return;
23024 }
23025
23026 extern bool dirty_screen;
23027
23028 void anim_hw_screen(bool force)
23029 {
23030 // if (force || myvsync)
23031 {
23032 ++cpoolbrush_index;
23033
23034 if(prv_mode)
23035 {
23036 if(Map.get_prvtime())
23037 {
23038 Map.set_prvtime(Map.get_prvtime()-1);
23039
23040 if(!Map.get_prvtime())
23041 {
23042 prv_warp=1;
23043 }
23044 }
23045 }
23046 if(AnimationOn)
23047 {
23048 animate_combos();
23049 update_freeform_combos();
23050 }
23051
23052 if(CycleOn)
23053 cycle_palette();
23054
23055 animate_coords();
23056 update_hw_screen();
23057 }
23058 }
23059
23060 void custom_vsync()
23061 {
23062 anim_hw_screen(true);
23063 }
23064
23065 void switch_out()
23066 {
23067 zcmusic_pause(zcmusic, ZCM_PAUSE);
23068 zc_midi_pause();
23069 }
23070
23071 void switch_in()
23072 {
23073 if(exiting_program)
23074 return;
23075 zcmusic_pause(zcmusic, ZCM_RESUME);
23076 zc_midi_resume();
23077 }
23078
23079 void Z_eventlog(const char *format,...)
23080 {
23081 format=format; //to prevent a compiler warning
23082 }
23083
23084 int32_t get_currdmap()
23085 {
23086 return zinit.start_dmap;
23087 }
23088
23089 int32_t get_dlevel()
23090 {
23091 return DMaps[zinit.start_dmap].level;
23092 }
23093
23094 int32_t get_currscr()
23095 {
23096 return Map.getCurrScr();
23097 }
23098
23099 int32_t get_currmap()
23100 {
23101 return Map.getCurrMap();
23102 }
23103
23104 int32_t get_homescr()
23105 {
23106 return DMaps[zinit.start_dmap].cont;
23107 }
23108
23109 int get_screen_for_world_xy(int x, int y)
23110 {
23111 return -1;
23112 }
23113
23114 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
23115 {
23116 //TODO remove as special case?? -DD
23117 if(item_type==itype_shield)
23118 {
23119 return 2;
23120 }
23121
23122 int id = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
23123 return id > -1 ? itemsbuf[id].fam_type : 0;
23124 }
23125
23126 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
23127 {
23128 if (game)
23129 {
23130 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
23131 return (result<0) ? 0 : itemsbuf[result].power;
23132 }
23133 return 1;
23134 }
23135
23136 int32_t current_item_id(int32_t itemtype, bool, bool, bool)
23137 {
23138 if (game)
23139 {
23140 int32_t result = -1;
23141 int32_t highestlevel = -1;
23142
23143 for (int32_t i = 0; i < MAXITEMS; i++)
23144 {
23145 if ((zq_ignore_item_ownership || game->get_item(i)) && itemsbuf[i].family == itemtype)
23146 {
23147 if (itemsbuf[i].fam_type >= highestlevel)
23148 {
23149 highestlevel = itemsbuf[i].fam_type;
23150 result = i;
23151 }
23152 }
23153 }
23154 return result;
23155 }
23156 for(int32_t i=0; i<MAXITEMS; i++)
23157 {
23158 if(itemsbuf[i].family==itemtype)
23159 return i;
23160 }
23161
23162 return -1;
23163 }
23164
23165
23166 bool can_use_item(int32_t item_type, int32_t item)
23167 {
23168 //these are here to bypass compiler warnings about unused arguments
23169 item_type=item_type;
23170 item=item;
23171
23172 return true;
23173 }
23174
23175 bool has_item(int32_t item_type, int32_t it)
23176 {
23177 //these are here to bypass compiler warnings about unused arguments
23178 item_type=item_type;
23179 it=it;
23180
23181 return true;
23182 }
23183
23184 int32_t get_bmaps(int32_t si)
23185 {
23186 //these are here to bypass compiler warnings about unused arguments
23187 si=si;
23188
23189 return 255;
23190 }
23191
23192 bool no_subscreen()
23193 {
23194 return false;
23195 }
23196
23197 12 static void allocate_crap()
23198 {
23199 12 filepath=(char*)malloc(2048);
23200 12 datapath=(char*)malloc(2048);
23201 12 midipath=(char*)malloc(2048);
23202 12 imagepath=(char*)malloc(2048);
23203 12 tmusicpath=(char*)malloc(2048);
23204 12 last_timed_save=(char*)malloc(2048);
23205
23206
1/2
✓ Branch 0 taken 12 times.
✗ Branch 1 not taken.
12 if(!filepath || !datapath || !imagepath || !midipath || !tmusicpath || !last_timed_save)
23207 {
23208 Z_error_fatal("Error: no memory for file paths!");
23209 }
23210
23211
23212 12 customtunes = (zctune*)malloc(sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23213 12 memset(customtunes, 0, sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23214
23215
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; ++i)
23216 {
23217 3072 customtunes[i].data=NULL;
23218 3072 }
23219
23220
2/2
✓ Branch 0 taken 3024 times.
✓ Branch 1 taken 12 times.
3036 for(int32_t i=0; i<MAXCUSTOMTUNES; i++)
23221 {
23222 3024 midi_string[i+4]=customtunes[i].title;
23223 3024 screen_midi_string[i+5]=customtunes[i].title;
23224 3024 }
23225
23226
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<WAV_COUNT; i++)
23227 {
23228
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(sfx_string[i]!=NULL) delete sfx_string[i];
23229 3072 customsfxdata[i].data=NULL;
23230 3072 sfx_string[i] = new char[36];
23231 3072 memset(sfx_string[i], 0, 36);
23232 3072 }
23233
23234
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXWPNS; i++)
23235 {
23236
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(weapon_string[i]!=NULL) delete weapon_string[i];
23237 3072 weapon_string[i] = new char[64];
23238 3072 memset(weapon_string[i], 0, 64);
23239 3072 }
23240
23241
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<MAXITEMS; i++)
23242 {
23243
1/4
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
3072 if(item_string[i]!=NULL) delete item_string[i];
23244 3072 item_string[i] = new char[64];
23245 3072 memset(item_string[i], 0, 64);
23246 3072 }
23247
23248
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<eMAXGUYS; i++)
23249 {
23250
1/4
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6144 if(guy_string[i]!=NULL) delete guy_string[i];
23251 6144 guy_string[i] = new char[64];
23252 6144 memset(guy_string[i], 0, 64);
23253 6144 }
23254
23255
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
23256 {
23257
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6144 times.
6144 delete ffscripts[i];
23258
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 ffscripts[i] = new script_data(ScriptType::FFC, i);
23259 6144 }
23260
23261
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
23262 {
23263
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemscripts[i];
23264
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemscripts[i] = new script_data(ScriptType::Item, i);
23265 3072 }
23266
23267
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
23268 {
23269
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete guyscripts[i];
23270
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 guyscripts[i] = new script_data(ScriptType::NPC, i);
23271 3072 }
23272
23273
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
23274 {
23275
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete screenscripts[i];
23276
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 screenscripts[i] = new script_data(ScriptType::Screen, i);
23277 3072 }
23278
23279
2/2
✓ Branch 0 taken 96 times.
✓ Branch 1 taken 12 times.
108 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
23280 {
23281
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 96 times.
96 delete globalscripts[i];
23282
1/2
✓ Branch 0 taken 96 times.
✗ Branch 1 not taken.
96 globalscripts[i] = new script_data(ScriptType::Global, i);
23283 96 }
23284
23285
2/2
✓ Branch 0 taken 60 times.
✓ Branch 1 taken 12 times.
72 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
23286 {
23287
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 delete playerscripts[i];
23288
1/2
✓ Branch 0 taken 60 times.
✗ Branch 1 not taken.
60 playerscripts[i] = new script_data(ScriptType::Hero, i);
23289 60 }
23290
23291
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23292 {
23293
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete lwpnscripts[i];
23294
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 lwpnscripts[i] = new script_data(ScriptType::Lwpn, i);
23295 3072 }
23296
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23297 {
23298
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete ewpnscripts[i];
23299
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 ewpnscripts[i] = new script_data(ScriptType::Ewpn, i);
23300 3072 }
23301
23302
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
23303 {
23304
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete dmapscripts[i];
23305
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 dmapscripts[i] = new script_data(ScriptType::DMap, i);
23306 3072 }
23307
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
23308 {
23309
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 delete itemspritescripts[i];
23310
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 itemspritescripts[i] = new script_data(ScriptType::ItemSprite, i);
23311 3072 }
23312
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
23313 {
23314
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete comboscripts[i];
23315
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 comboscripts[i] = new script_data(ScriptType::Combo, i);
23316 6144 }
23317
2/2
✓ Branch 0 taken 6144 times.
✓ Branch 1 taken 12 times.
6156 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
23318 {
23319
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 delete genericscripts[i];
23320
1/2
✓ Branch 0 taken 6144 times.
✗ Branch 1 not taken.
6144 genericscripts[i] = new script_data(ScriptType::Generic, i);
23321 6144 }
23322
2/2
✓ Branch 0 taken 3072 times.
✓ Branch 1 taken 12 times.
3084 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
23323 {
23324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3072 times.
3072 delete subscreenscripts[i];
23325
1/2
✓ Branch 0 taken 3072 times.
✗ Branch 1 not taken.
3072 subscreenscripts[i] = new script_data(ScriptType::EngineSubscreen, i);
23326 3072 }
23327 12 }
23328
23329 static void handle_sentry_tags()
23330 {
23331 static bool sentry_first_time = true;
23332
23333 static MapCursor sentry_last_map_cursor;
23334 if (Map.getCursor() != sentry_last_map_cursor || sentry_first_time)
23335 {
23336 sentry_last_map_cursor = Map.getCursor();
23337 zapp_reporting_set_tag("cursor.map", sentry_last_map_cursor.map);
23338 zapp_reporting_set_tag("cursor.screen", sentry_last_map_cursor.screen);
23339 zapp_reporting_set_tag("cursor.viewscr", sentry_last_map_cursor.viewscr);
23340 zapp_reporting_set_tag("cursor.size", sentry_last_map_cursor.size);
23341 }
23342
23343 static bool sentry_last_is_compact;
23344 if (is_compact != sentry_last_is_compact || sentry_first_time)
23345 {
23346 sentry_last_is_compact = is_compact;
23347 zapp_reporting_set_tag("compact", sentry_last_is_compact);
23348 }
23349
23350 sentry_first_time = false;
23351 }
23352
23353 // Removes the top layer encoding from a quest file. See open_quest_file.
23354 // This has zero impact on the contents of the quest file. There should be no way for this to
23355 // break anything.
23356 static void do_unencrypt_qst_command(const char* input_filename, const char* output_filename)
23357 {
23358 // If the file is already an unencrypted packfile, there's nothing to do.
23359 PACKFILE* pf_check = pack_fopen_password(input_filename, F_READ_PACKED, "");
23360 pack_fclose(pf_check);
23361 if (pf_check) return;
23362
23363 int32_t error;
23364 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23365 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE_PACKED, "");
23366 int c;
23367 while ((c = pack_getc(pf)) != EOF)
23368 {
23369 pack_putc(c, pf2);
23370 }
23371 pack_fclose(pf);
23372 pack_fclose(pf2);
23373 clear_quest_tmpfile();
23374 }
23375
23376 // This will remove the PACKFILE compression. Incidentally, it also removes the top encoding layer.
23377 static void do_uncompress_qst_command(const char* input_filename, const char* output_filename)
23378 {
23379 auto unencrypted_result = try_open_maybe_legacy_encoded_file(input_filename, ENC_STR, nullptr, QH_NEWIDSTR, QH_IDSTR);
23380 if (unencrypted_result.not_found)
23381 {
23382 printf("qst not found\n");
23383 zq_exit(1);
23384 }
23385 if (!unencrypted_result.compressed && !unencrypted_result.encrypted)
23386 {
23387 // If the file is already an uncompressed file, there's nothing to do but copy it.
23388 fs::copy(input_filename, output_filename);
23389 return;
23390 }
23391
23392 pack_fclose(unencrypted_result.decoded_pf);
23393
23394 int32_t error;
23395 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23396 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE, "");
23397 int c;
23398 while ((c = pack_getc(pf)) != EOF)
23399 {
23400 pack_putc(c, pf2);
23401 }
23402 pack_fclose(pf);
23403 pack_fclose(pf2);
23404 clear_quest_tmpfile();
23405 }
23406
23407 // Copy a quest file by loading and resaving, exactly like if the user did it in the UI.
23408 // Note there could be changes introduced in the loading or saving functions. These are
23409 // typically for compatability, but could possibly be a source of bugs.
23410 3 static void do_copy_qst_command(const char* input_filename, const char* output_filename)
23411 {
23412 3 set_headless_mode();
23413
23414 // We need to init some stuff before loading a quest file will work.
23415 3 int fake_errno = 0;
23416 3 allegro_errno = &fake_errno;
23417 3 get_qst_buffers();
23418
23419 3 int ret = load_quest(input_filename, false);
23420
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
3 if (ret)
23421 {
23422 zq_exit(ret);
23423 }
23424
23425 3 ret = save_quest(output_filename, false);
23426 3 zq_exit(ret);
23427 3 }
23428
23429 int32_t Awpn=-1, Bwpn=-1, Xwpn = -1, Ywpn = -1;
23430 84 sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations, portals;
23431 int32_t exittimer = 10000, exittimer2 = 100;
23432
23433 1 static bool partial_load_test(const char* test_dir)
23434 {
23435
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 auto classic_path = fs::path(test_dir) / "replays/classic_1st.qst";
23436
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 int ret = load_quest(classic_path.string().c_str(), false);
23437
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23438 {
23439 printf("failed to load classic_1st.qst: ret == %d\n", ret);
23440 return false;
23441 }
23442
23443 1 int cont = DMaps[0].cont;
23444
23445 // Skip same stuff as used in zq_tiles.cpp for grabbing tiles from a qst.
23446 byte skip_flags[4];
23447
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 26 times.
27 for (int i=0; i<skip_max; ++i)
23448
1/2
✓ Branch 0 taken 26 times.
✗ Branch 1 not taken.
26 set_bit(skip_flags,i,1);
23449
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_tiles,0);
23450
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 set_bit(skip_flags,skip_header,0);
23451 1 zquestheader tempheader{};
23452
3/6
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
1 auto ptux_path = fs::path(test_dir) / "quests/PTUX.qst";
23453
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 ret = loadquest(ptux_path.string().c_str(), &tempheader, &QMisc, customtunes, false, skip_flags);
23454
23455
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23456 {
23457 printf("failed to load PTUX.qst: ret == %d\n", ret);
23458 return false;
23459 }
23460
23461
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (DMaps[0].cont != cont)
23462 {
23463 printf("unexpected modification: DMaps[0].cont == %d, should be %d\n", DMaps[0].cont, cont);
23464 return false;
23465 }
23466
23467 // TODO should run replay. Currently, resaving classic_1st.qst fails its replay (see test_save in test_zeditor.py)
23468
23469 1 return true;
23470 1 }
23471
23472 template <typename ...Params>
23473 [[noreturn]] void FatalConsole(const char *format, Params&&... params)
23474 {
23475 FFCore.ZScriptConsole(CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"");
23476 Z_error_fatal(format, std::forward<Params>(params)...);
23477 }
23478
23479 40 static BITMAP* load_asset_bmp(const char* path)
23480 {
23481 40 BITMAP* bmp = load_bmp(path, nullptr);
23482
1/2
✓ Branch 0 taken 40 times.
✗ Branch 1 not taken.
40 if (!bmp)
23483 Z_error_fatal("Failed to load required asset: %s\n", path);
23484 40 return bmp;
23485 }
23486
23487 8 static void load_asset_pal(PALETTE pal, const char* path)
23488 {
23489 8 BITMAP* bmp = load_bmp(path, pal);
23490
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!bmp)
23491 Z_error_fatal("Failed to load required asset: %s\n", path);
23492 8 }
23493
23494 8 static MIDI* load_asset_midi(const char* path)
23495 {
23496 8 MIDI* midi = load_midi(path);
23497
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!midi)
23498 Z_error_fatal("Failed to load required asset: %s\n", path);
23499 8 return midi;
23500 }
23501
23502 BITMAP* asset_icons_bmp;
23503 BITMAP* asset_engravings_bmp;
23504 BITMAP* asset_mouse_bmp;
23505 BITMAP* asset_select_bmp;
23506 BITMAP* asset_arrows_bmp;
23507 MIDI* asset_tunes_midi;
23508 PALETTE asset_pal;
23509
23510 8 static void load_assets()
23511 {
23512 8 asset_icons_bmp = load_asset_bmp("assets/editor/icons.bmp");
23513 8 asset_engravings_bmp = load_asset_bmp("assets/editor/engravings.bmp");
23514 8 asset_mouse_bmp = load_asset_bmp("assets/editor/mouse.bmp");
23515 8 asset_select_bmp = load_asset_bmp("assets/editor/select.bmp");
23516 8 asset_arrows_bmp = load_asset_bmp("assets/editor/arrows.bmp");
23517 8 asset_tunes_midi = load_asset_midi("assets/editor/tunes.mid");
23518 8 load_asset_pal(asset_pal, "assets/editor/pal.bmp");
23519 8 }
23520
23521 static bool application_has_loaded;
23522
23523 8 int32_t main(int32_t argc,char **argv)
23524 {
23525 8 int test_zc_arg = used_switch(argc, argv, "-test-zc");
23526
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (test_zc_arg > 0)
23527 1 set_headless_mode();
23528
23529 8 zalleg_setup_allegro(App::zquest, argc, argv);
23530 8 allocate_crap();
23531
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 set_should_zprint_cb([]() {
23532 return get_qr(qr_SCRIPTERRLOG) || DEVLEVEL > 0;
23533 });
23534
23535 8 int package_arg = used_switch(argc, argv, "-package");
23536
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (package_arg > 0)
23537 {
23538 if (package_arg + 3 > argc)
23539 {
23540 printf("%d\n", argc);
23541 printf("expected -package <game.qst> <package name>\n");
23542 zq_exit(1);
23543 }
23544
23545 const char* input_filename = argv[package_arg + 1];
23546 const char* package_name = argv[package_arg + 2];
23547 if (auto error = package_create(input_filename, package_name))
23548 Z_error_fatal("%s\n", error->c_str());
23549 zq_exit(0);
23550 }
23551
23552 8 int copy_qst_arg = used_switch(argc, argv, "-copy-qst");
23553
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 5 times.
8 if (copy_qst_arg > 0)
23554 {
23555
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if (copy_qst_arg + 3 > argc)
23556 {
23557 printf("%d\n", argc);
23558 printf("expected -copy-qst <input> <output>\n");
23559 zq_exit(1);
23560 }
23561
23562 3 const char* input_filename = argv[copy_qst_arg + 1];
23563 3 const char* output_filename = argv[copy_qst_arg + 2];
23564 3 do_copy_qst_command(input_filename, output_filename);
23565 3 }
23566
23567 8 Z_title("ZQuest Classic Editor, %s", getVersionString());
23568
23569
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!get_qst_buffers())
23570 {
23571 Z_error_fatal("Error");
23572 }
23573
23574 8 undocombobuf.clear();
23575 8 undocombobuf.resize(MAXCOMBOS);
23576
23577
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if((newundotilebuf=(tiledata*)malloc(NEWMAXTILES*sizeof(tiledata)))==NULL)
23578 {
23579 Z_error_fatal("Error: no memory for tile undo buffer!");
23580 }
23581
23582 8 memset(newundotilebuf, 0, NEWMAXTILES*sizeof(tiledata));
23583
23584 8 Z_message("Resetting new tile buffer...");
23585 8 newtilebuf = (tiledata*)malloc(NEWMAXTILES*sizeof(tiledata));
23586
23587
2/2
✓ Branch 0 taken 1930500 times.
✓ Branch 1 taken 8 times.
1930508 for(int32_t j=0; j<NEWMAXTILES; j++)
23588 1930500 newtilebuf[j].data=NULL;
23589
23590 8 Z_message("OK\n");
23591
23592 8 zc_srand(time(0));
23593
23594
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 7 times.
8 if (test_zc_arg > 0)
23595 {
23596 1 set_headless_mode();
23597
23598
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (test_zc_arg + 1 > argc)
23599 {
23600 printf("%d\n", argc);
23601 printf("expected -test-zc <path to test dir>\n");
23602 zq_exit(1);
23603 }
23604
23605 1 const char* test_dir = argv[test_zc_arg + 1];
23606
23607 // We need to init some stuff before loading a quest file will work.
23608 1 int fake_errno = 0;
23609 1 allegro_errno = &fake_errno;
23610 1 get_qst_buffers();
23611
23612 1 bool success = true;
23613
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!partial_load_test(test_dir))
23614 {
23615 success = false;
23616 printf("partial_load_test failed\n");
23617 }
23618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (success)
23619 1 printf("all tests passed\n");
23620 1 zq_exit(success ? 0 : 1);
23621 1 }
23622
23623 8 int unencrypt_qst_arg = used_switch(argc, argv, "-unencrypt-qst");
23624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (unencrypt_qst_arg > 0)
23625 {
23626 if (unencrypt_qst_arg + 3 > argc)
23627 {
23628 printf("%d\n", argc);
23629 printf("expected -unencrypt-qst <input> <output>\n");
23630 zq_exit(1);
23631 }
23632
23633 const char* input_filename = argv[unencrypt_qst_arg + 1];
23634 const char* output_filename = argv[unencrypt_qst_arg + 2];
23635 do_unencrypt_qst_command(input_filename, output_filename);
23636 zq_exit(0);
23637 }
23638
23639 8 int uncompress_qst_arg = used_switch(argc, argv, "-uncompress-qst");
23640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if (uncompress_qst_arg > 0)
23641 {
23642 if (uncompress_qst_arg + 3 > argc)
23643 {
23644 printf("%d\n", argc);
23645 printf("expected -uncompress-qst <input> <output>\n");
23646 zq_exit(1);
23647 }
23648
23649 const char* input_filename = argv[uncompress_qst_arg + 1];
23650 const char* output_filename = argv[uncompress_qst_arg + 2];
23651 do_uncompress_qst_command(input_filename, output_filename);
23652 zq_exit(0);
23653 }
23654
23655 8 three_finger_flag=false;
23656
23657 #ifndef __EMSCRIPTEN__
23658
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(zc_get_config("zquest","open_debug_console",0))
23659 initConsole();
23660 #endif
23661
23662 LOCK_VARIABLE(lastfps);
23663
23664 LOCK_VARIABLE(framecnt);
23665 LOCK_FUNCTION(fps_callback);
23666
23667
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
23668 {
23669 Z_error_fatal("couldn't allocate timer");
23670 }
23671
23672
23673 LOCK_VARIABLE(dclick_status);
23674 LOCK_VARIABLE(dclick_time);
23675 8 lock_dclick_function();
23676 8 install_int(dclick_check, 20);
23677
23678 8 set_gfx_mode(GFX_TEXT,80,50,0,0);
23679
23680 8 load_assets();
23681
23682 8 Z_message("OK\n");
23683
23684
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 helpstr = util::read_text_file("docs/zquest.txt");
23685
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 zstringshelpstr = util::read_text_file("docs/zstrings.txt");
23686
23687 // loading data files...
23688
23689 8 filepath[0]=temppath[0]=0;
23690
23691 8 const char *default_path="";
23692
23693 8 strcpy(datapath,zc_get_config("zquest",data_path_name,default_path));
23694 8 strcpy(midipath,zc_get_config("zquest",midi_path_name,default_path));
23695 8 strcpy(imagepath,zc_get_config("zquest",image_path_name,default_path));
23696 8 strcpy(tmusicpath,zc_get_config("zquest",tmusic_path_name,default_path));
23697 8 chop_path(datapath);
23698 8 chop_path(midipath);
23699 8 chop_path(imagepath);
23700 8 chop_path(tmusicpath);
23701
23702 8 DisableLPalShortcuts = zc_get_config("zquest","dis_lpal_shortcut",1);
23703 8 DisableCompileConsole = zc_get_config("zquest","internal_compile_console",0);
23704 8 MouseScroll = zc_get_config("zquest","mouse_scroll",0);
23705 8 MMapCursorStyle = zc_get_config("zquest","cursorblink_style",1);
23706 8 LayerDitherBG = zc_get_config("zquest", "layer_dither_bg", -1);
23707 8 LayerDitherSz = zc_get_config("zquest", "layer_dither_sz", 3);
23708 8 InvalidBG = zc_get_config("zquest", "invalid_bg", 0);
23709 8 TileProtection = zc_get_config("zquest","tile_protection",1);
23710 8 ComboProtection = zc_get_config("zquest","combo_protection",TileProtection);
23711 8 ShowGrid = zc_get_config("zquest","show_grid",0);
23712 8 ShowCurScreenOutline = zc_get_config("zquest","show_current_screen_outline",1);
23713 8 ShowScreenGrid = zc_get_config("zquest","show_screen_grid",0);
23714 8 ShowRegionGrid = zc_get_config("zquest","show_region_grid",1);
23715 8 GridColor = zc_get_config("zquest","grid_color",15);
23716 8 CmbCursorCol = zc_get_config("zquest","combo_cursor_color",15);
23717 8 TilePgCursorCol = zc_get_config("zquest","tpage_cursor_color",15);
23718 8 CmbPgCursorCol = zc_get_config("zquest","cpage_cursor_color",15);
23719 8 TTipHLCol = zc_get_config("zquest","ttip_hl_color",13);
23720 8 CheckerCol1 = zc_get_config("zquest","checker_color_1",7);
23721 8 CheckerCol2 = zc_get_config("zquest","checker_color_2",8);
23722 8 SnapshotFormat = zc_get_config("zquest","snapshot_format",3);
23723 8 SnapshotScale = zc_get_config("zquest","snapshot_scale",2);
23724 8 SavePaths = zc_get_config("zquest","save_paths",1);
23725 8 CycleOn = zc_get_config("zquest","cycle_on",1);
23726 8 ShowFPS = zc_get_config("zquest","showfps",0)!=0;
23727 8 SaveDragResize = zc_get_config("zquest","save_drag_resize",0)!=0;
23728 8 DragAspect = zc_get_config("zquest","drag_aspect",0)!=0;
23729 8 SaveWinPos = zc_get_config("zquest","save_window_position",0)!=0;
23730 8 ComboBrush = zc_get_config("zquest","combo_brush",0);
23731 8 FloatBrush = zc_get_config("zquest","float_brush",0);
23732 8 AutoBrush = zc_get_config("zquest","autobrush",1);
23733 8 LinkedScroll = zc_get_config("zquest","linked_comboscroll",0);
23734 8 allowHideMouse = zc_get_config("ZQ_GUI","allowHideMouse",0);
23735 8 ShowFavoriteComboModes = zc_get_config("ZQ_GUI","show_fav_combo_modes",1);
23736 8 NoHighlightLayer0 = zc_get_config("zquest","no_highlight_layer0",0);
23737 8 RulesetDialog = zc_get_config("zquest","rulesetdialog",1);
23738 8 EnableTooltips = zc_get_config("zquest","enable_tooltips",1);
23739 8 TooltipsHighlight = zc_get_config("zquest","ttip_highlight",1);
23740 8 tooltip_maxtimer = vbound(zc_get_config("zquest","ttip_timer",30),0,60*60);
23741 8 ShowFFScripts = zc_get_config("zquest","showffscripts",1);
23742 8 ShowSquares = zc_get_config("zquest","showsquares",1);
23743 8 ShowFFCs = zc_get_config("zquest","showffcs",0);
23744 8 ShowInfo = zc_get_config("zquest","showinfo",1);
23745 8 skipLayerWarning = zc_get_config("zquest","skip_layer_warning",0);
23746 8 numericalFlags = zc_get_config("zquest","numerical_flags",0);
23747 8 ViewLayer2BG = zc_get_config("zquest","layer2_bg",0);
23748 8 ViewLayer3BG = zc_get_config("zquest","layer3_bg",0);
23749 8 ActiveLayerHighlight = zc_get_config("zquest","hl_active_lyr",0);
23750 8 DragCenterOfSquares = zc_get_config("zquest","drag_squares_from_center",0);
23751
23752 8 OpenLastQuest = zc_get_config("zquest","open_last_quest",0);
23753 8 ShowMisalignments = zc_get_config("zquest","show_misalignments",0);
23754 8 AnimationOn = zc_get_config("zquest","animation_on",1);
23755 8 AutoBackupRetention = zc_get_config("zquest","auto_backup_retention",2);
23756 8 AutoSaveInterval = zc_get_config("zquest","auto_save_interval",6);
23757 8 AutoSaveRetention = zc_get_config("zquest","auto_save_retention",2);
23758 8 UncompressedAutoSaves = zc_get_config("zquest","uncompressed_auto_saves",1);
23759 8 OverwriteProtection = zc_get_config("zquest","overwrite_prevention",0)!=0;
23760 8 ImportMapBias = zc_get_config("zquest","import_map_bias",0);
23761
23762 8 KeyboardRepeatDelay = zc_get_config("zquest","keyboard_repeat_delay",300);
23763 8 KeyboardRepeatRate = zc_get_config("zquest","keyboard_repeat_rate",80);
23764
23765 // Frameskip = zc_get_config("zquest","frameskip",0); //todo: this is not actually supported yet.
23766 8 RequestedFPS = zc_get_config("zquest","fps",60);
23767
23768 // Autofill for Combo Page, Tile Page
23769 8 PreFillTileEditorPage = zc_get_config("zquest","PreFillTileEditorPage",0);
23770 8 PreFillComboEditorPage = zc_get_config("zquest","PreFillComboEditorPage",0);
23771
23772 8 pixeldb = zc_get_config("ZQ_GUI","bottom_8_pixels",0);
23773 8 infobg = zc_get_config("ZQ_GUI","info_text_bg",0);
23774
23775 8 large_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_large",0);
23776 8 compact_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_compact",1);
23777
23778 8 compact_square_panels = zc_get_config("ZQ_GUI","square_panels_compact",0);
23779
23780 8 large_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_large",0);
23781 8 compact_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_compact",1);
23782 8 large_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_large",1);
23783 8 compact_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_compact",1);
23784
23785
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(zc_get_config("gui","disable_window_resizing",0))
23786 all_set_resize_flag(false);
23787
23788 8 load_hotkeys();
23789
23790 #ifdef _WIN32
23791 zqUseWin32Proc = zc_get_config("zquest","zq_win_proc_fix",0);
23792
23793 #endif
23794
23795
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!render_timer_start())
23796 {
23797 Z_error_fatal("couldn't allocate timer");
23798 }
23799
23800 8 byte layermask = zc_get_config("zquest","layer_mask",0x7F);
23801 8 int32_t usefullscreen = zc_get_config("zquest","fullscreen",0);
23802 8 tempmode = (usefullscreen == 0 ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN);
23803
23804
2/2
✓ Branch 0 taken 56 times.
✓ Branch 1 taken 8 times.
64 for(int32_t x=0; x<7; x++)
23805 {
23806 56 LayerMaskInt[x]=get_bit(&layermask,x);
23807 56 }
23808
23809 8 DuplicateAction[0] = zc_get_config("zquest","normal_duplicate_action",2);
23810 8 DuplicateAction[1] = zc_get_config("zquest","horizontal_duplicate_action",0);
23811 8 DuplicateAction[2] = zc_get_config("zquest","vertical_duplicate_action",0);
23812 8 DuplicateAction[3] = zc_get_config("zquest","both_duplicate_action",0);
23813 8 LeechUpdate = zc_get_config("zquest","leech_update",500);
23814 8 LeechUpdateTiles = zc_get_config("zquest","leech_update_tiles",1);
23815 8 OnlyCheckNewTilesForDuplicates = zc_get_config("zquest","only_check_new_tiles_for_duplicates",0);
23816 //gui_colorset = zc_get_config("zquest","gui_colorset",0);
23817
23818 8 strcpy(last_timed_save,zc_get_config("zquest","last_timed_save",""));
23819
23820 8 midi_volume = zc_get_config("zquest", "midi", 255);
23821
23822 8 abc_patternmatch = zc_get_config("zquest", "lister_pattern_matching", 1);
23823 8 NoScreenPreview = zc_get_config("zquest", "no_preview", 0);
23824
23825 8 monochrome_console = zc_get_config("CONSOLE","monochrome_debuggers",0)?1:0;
23826
23827 8 try_recovering_missing_scripts = 0;//zc_get_config("Compiler", "try_recovering_missing_scripts",0);
23828 //We need to remove all of the zeldadx refs to the config file for zquest.
23829
23830 8 set_keyboard_rate(KeyboardRepeatDelay,KeyboardRepeatRate);
23831
23832 8 is_compact = zc_get_config("ZQ_GUI","compact_mode",1);
23833 8 mapscreenbmp = nullptr;
23834 8 brushbmp = nullptr;
23835 8 brushscreen = nullptr;
23836 8 screen2 = nullptr;
23837 8 tmp_scr = nullptr;
23838 8 menu1 = nullptr;
23839 8 menu3 = nullptr;
23840
23841
2/2
✓ Branch 0 taken 10080 times.
✓ Branch 1 taken 8 times.
10088 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
23842 {
23843 10080 favorite_combos[i]=-1;
23844 10080 pool_combos[i].clear();
23845 10080 }
23846 8 FavoriteComboPage = 0;
23847 8 pool_dirty = true;
23848
23849
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(used_switch(argc,argv,"-d"))
23850 {
23851 set_debug(!strcmp(zquestpwd,zc_get_config("zquest","debug_this","")));
23852 }
23853
23854 8 zcmusic_init();
23855 8 zcmixer = zcmixer_create();
23856 1088 install_int_ex([](){ zcmusic_poll(); }, MSEC_TO_TIMER(25));
23857
23858 8 set_color_depth(8);
23859
23860 8 set_close_button_callback((void (*)()) hit_close_button);
23861
23862
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(used_switch(argc,argv,"-fullscreen"))
23863 {
23864 tempmode = GFX_AUTODETECT_FULLSCREEN;
23865 }
23866
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 else if(used_switch(argc,argv,"-windowed"))
23867 {
23868 tempmode=GFX_AUTODETECT_WINDOWED;
23869 }
23870
23871 8 zq_screen_w = LARGE_W;
23872 8 zq_screen_h = LARGE_H;
23873 8 window_width = zc_get_config("zquest","window_width",-1);
23874 8 window_height = zc_get_config("zquest","window_height",-1);
23875 8 auto [w, h] = zc_get_default_display_size(LARGE_W, LARGE_H, window_width, window_height);
23876
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 int32_t videofail = is_headless() ? 0 : (set_gfx_mode(tempmode,w,h,zq_screen_w,zq_screen_h));
23877
23878 //extra block here is intentional
23879
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(videofail!=0)
23880 {
23881 quit_game();
23882 allegro_exit();
23883 }
23884
23885 8 zalleg_create_window();
23886 8 Z_message("gfx mode set at -%d %dbpp %d x %d \n",
23887 8 tempmode, get_color_depth(), zq_screen_w, zq_screen_h);
23888
23889 8 set_window_title("ZC Editor");
23890
23891 8 load_size_poses();
23892
23893
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
23894 {
23895 // Just in case.
23896 while (!all_get_display()) {
23897 al_rest(1);
23898 }
23899
23900 al_resize_display(all_get_display(), w, h);
23901 }
23902
23903
23904 #ifndef __EMSCRIPTEN__
23905
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 if (!all_get_fullscreen_flag() && !is_headless()) {
23906 al_resize_display(all_get_display(), w, h);
23907
23908 int window_w = al_get_display_width(all_get_display());
23909 int window_h = al_get_display_height(all_get_display());
23910
23911 int new_x = zc_get_config("zquest","window_x",0);
23912 int new_y = zc_get_config("zquest","window_y",0);
23913 if(zc_get_config("zquest","save_window_position",0) && (new_x || new_y))
23914 {
23915 //load saved position
23916 //already stored in new_x/new_y
23917 }
23918 else
23919 {
23920 //Get default position
23921 ALLEGRO_MONITOR_INFO info;
23922 al_get_monitor_info(0, &info);
23923
23924 int mw = (info.x2 - info.x1);
23925 int mh = (info.y2 - info.y1);
23926 new_x = mw / 2 - window_w / 2;
23927 new_y = mh / 2 - window_h / 2;
23928 //Don't spawn the window too far down (taskbar?)
23929 if(new_y + window_h > mh - 72)
23930 new_y = mh-72-window_h;
23931 }
23932 #ifdef ALLEGRO_MACOSX
23933 if (zc_get_config("zquest","save_window_position",0))
23934 al_set_window_position(all_get_display(), new_x, new_y);
23935 #else
23936 al_set_window_position(all_get_display(), new_x, new_y);
23937 #endif
23938 }
23939 #endif
23940
23941 8 position_mouse(zq_screen_w/2,zq_screen_h/2);
23942
23943 8 dmapbmp_small = create_bitmap_ex(8,65,33);
23944 8 dmapbmp_large = create_bitmap_ex(8,177,81);
23945
23946
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(!screen2 || !tmp_scr || !menu1 || !menu3 || !dmapbmp_large || !dmapbmp_large || !brushbmp || !brushscreen)// || !brushshadowbmp )
23947 {
23948 Z_error_fatal("Failed to create system bitmaps!\n");
23949 return 1;
23950 }
23951
23952 8 int quick_assign_arg = used_switch(argc, argv, "-quick-assign");
23953
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 6 times.
8 if (quick_assign_arg > 0)
23954 {
23955 6 is_zq_replay_test = true;
23956 6 set_headless_mode();
23957
23958 6 int load_ret = load_quest(argv[quick_assign_arg + 1], false);
23959 6 bool success = load_ret == qe_OK;
23960
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23961 {
23962 printf("Failed to load quest: %d\n", load_ret);
23963 zq_exit(1);
23964 }
23965
23966 6 success = do_compile_and_slots(1, false);
23967
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23968 {
23969 printf("Failed to compile\n");
23970 zq_exit(1);
23971 }
23972
23973 6 success = save_quest(argv[quick_assign_arg + 1], false) == 0;
23974
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!success)
23975 {
23976 printf("Failed to save quest\n");
23977 zq_exit(1);
23978 }
23979
23980 6 zq_exit(0);
23981 6 }
23982
23983 8 int smart_assign_arg = used_switch(argc, argv, "-smart-assign");
23984
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (smart_assign_arg > 0)
23985 {
23986 is_zq_replay_test = true;
23987 set_headless_mode();
23988
23989 int load_ret = load_quest(argv[smart_assign_arg + 1], false);
23990 bool success = load_ret == qe_OK;
23991 if (!success)
23992 {
23993 printf("Failed to load quest: %d\n", load_ret);
23994 zq_exit(1);
23995 }
23996
23997 success = do_compile_and_slots(2, false);
23998 if (!success)
23999 {
24000 printf("Failed to compile\n");
24001 zq_exit(1);
24002 }
24003
24004 success = save_quest(argv[smart_assign_arg + 1], false) == 0;
24005 if (!success)
24006 {
24007 printf("Failed to save quest\n");
24008 zq_exit(1);
24009 }
24010
24011 zq_exit(0);
24012 }
24013
24014 8 int export_strings_arg = used_switch(argc, argv, "-export-strings");
24015
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if (export_strings_arg > 0)
24016 {
24017
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (export_strings_arg + 3 > argc)
24018 {
24019 printf("%d\n", argc);
24020 printf("expected -export-strings input.qst output.tsv\n");
24021 zq_exit(1);
24022 }
24023
24024 1 is_zq_replay_test = true;
24025 1 set_headless_mode();
24026
24027 1 int load_ret = load_quest(argv[export_strings_arg + 1], false);
24028 1 bool success = load_ret == qe_OK;
24029
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
24030 {
24031 printf("Failed to load quest: %d\n", load_ret);
24032 zq_exit(1);
24033 }
24034
24035 1 success = save_strings_tsv(argv[export_strings_arg + 2]);
24036
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
24037 {
24038 printf("Failed to export strings\n");
24039 zq_exit(1);
24040 }
24041
24042 1 zq_exit(0);
24043 1 }
24044
24045
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if (!is_headless())
24046 {
24047 zc_set_palette(asset_pal);
24048 get_palette(RAMpal);
24049 load_colorset(gui_colorset);
24050 zc_set_palette(RAMpal);
24051 clear_to_color(screen,vc(0));
24052 }
24053
24054 8 zScript = string();
24055 8 strcpy(zScriptBytes, "0 Bytes in Buffer");
24056
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 8 times.
20 for(int32_t i=0; i<MOUSE_BMP_MAX; i++)
24057 {
24058
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t j=0; j<4; j++)
24059 {
24060 48 mouse_bmp[i][j] = NULL;
24061 48 mouse_bmp_1x[i][j] = NULL;
24062 48 }
24063 12 }
24064 8 load_mice();
24065 8 gui_mouse_focus=0;
24066 8 MouseSprite::set(ZQM_NORMAL);
24067 8 render_zq(); // Ensure the rendering bitmaps are setup.
24068
24069 #ifdef __EMSCRIPTEN__
24070 em_mark_ready_status();
24071 #endif
24072
24073 8 load_icons();
24074
24075 8 bool load_last_timed_save=false;
24076
24077 8 load_recent_quests();
24078 8 refresh_recent_menu();
24079 //clearConsole();
24080
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
8 if((last_timed_save[0]!=0)&&(exists(last_timed_save)))
24081 {
24082 if(jwin_alert("ZQuest","It appears that ZQuest crashed last time.","Would you like to load the last timed save?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
24083 {
24084 int32_t ret = load_quest(last_timed_save);
24085
24086 if(ret == qe_OK)
24087 {
24088 strcpy(filepath,last_timed_save);
24089 load_last_timed_save=true;
24090 saved=false;
24091 }
24092 else
24093 {
24094 jwin_alert("Error","Unable to reload the last timed save.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
24095 }
24096 }
24097 }
24098
24099
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
8 if(!load_last_timed_save)
24100 {
24101 1 strcpy(filepath,zc_get_config("zquest",last_quest_name,""));
24102
24103
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(argc>1 && argv[1][0]!='-')
24104 {
24105 int32_t ret = load_quest(argv[1]);
24106
24107 if(ret == qe_OK)
24108 {
24109 first_save=true;
24110 strcpy(filepath,argv[1]);
24111 refresh(rALL);
24112 }
24113 }
24114
2/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 else if(OpenLastQuest&&filepath[0]&&exists(filepath)&&!used_switch(argc,argv,"-new"))
24115 {
24116 int32_t ret = load_quest(filepath);
24117
24118 if(ret == qe_OK)
24119 {
24120 first_save=true;
24121 refresh(rALL);
24122 }
24123 else
24124 {
24125 filepath[0]=temppath[0]=0;
24126 first_save=false;
24127 }
24128 }
24129 else
24130 {
24131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (onNew() == D_CLOSE)
24132 {
24133 1 Z_message("User canceled creating new quest, closing.\n");
24134 1 exit(0);
24135 }
24136
24137 //otherwise the blank quest gets the name of the last loaded quest... not good! -DD
24138 filepath[0]=temppath[0]=0;
24139 first_save=false;
24140 }
24141 }
24142
24143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if(used_switch(argc,argv,"-q"))
24144 {
24145 Z_message("-q switch used, quitting program.\n");
24146 zq_exit(0);
24147 }
24148
24149
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXITEMS; x++)
24150 {
24151 lens_hint_item[x][0]=0;
24152 lens_hint_item[x][1]=0;
24153 }
24154
24155
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int32_t x=0; x<MAXWPNS; x++)
24156 {
24157 lens_hint_weapon[x][0]=0;
24158 lens_hint_weapon[x][1]=0;
24159 }
24160
24161 7 load_selections();
24162 7 load_arrows();
24163 7 clear_to_color(menu1,vc(0));
24164 7 DIALOG_PLAYER *player2=init_dialog(dialogs,-1);
24165
24166 7 get_palette(RAMpal);
24167
24168 7 rgb_map = &zq_rgb_table;
24169
24170 #ifdef __EMSCRIPTEN__
24171 {
24172 int qs_map = EM_ASM_INT({
24173 return new URL(location.href).searchParams.get('map') ?? -1;
24174 });
24175 int qs_screen = EM_ASM_INT({
24176 return new URL(location.href).searchParams.get('screen') ?? -1;
24177 });
24178 if (qs_map != -1 && qs_screen != -1) {
24179 Map.setCurrMap(qs_map);
24180 Map.setCurrScr(qs_screen);
24181 }
24182 }
24183 #endif
24184
24185 // setup_combo_animations();
24186 7 pause_refresh = false;
24187 7 refresh_pal();
24188 7 refresh(rALL);
24189
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_width_menu.size(); ++q)
24190 brush_width_menu.at(q)->select(q==0);
24191
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 for(int q = 0; q < brush_height_menu.size(); ++q)
24192 brush_height_menu.at(q)->select(q==0);
24193 7 set_filltype(1);
24194
24195 7 rebuild_trans_table();
24196
24197
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if (!is_headless())
24198 {
24199 set_display_switch_mode(SWITCH_BACKGROUND);
24200 set_display_switch_callback(SWITCH_OUT, switch_out);
24201 set_display_switch_callback(SWITCH_IN, switch_in);
24202 }
24203
24204
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!update_dialog(player2))
24205 exiting_program = true;
24206 //clear_keybuf();
24207 7 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
24208 7 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
24209
24210 7 fix_drawing_mode_menu();
24211
24212
24213 #ifdef _WIN32
24214
24215 if(zqUseWin32Proc != FALSE)
24216 {
24217 al_trace("Config file warning: \"zq_win_proc_fix\" enabled switch found. This can cause crashes on some computers.\n");
24218 win32data.zqSetDefaultThreadPriority(0);
24219 win32data.zqSetCustomCallbackProc(al_get_win_window_handle(all_get_display()));
24220 }
24221
24222 #endif
24223
24224 7 time(&auto_save_time_start);
24225
24226 7 FFCore.init();
24227 7 ZQincludePaths = FFCore.includePaths;
24228
24229 7 Map.setCopyFFC(-1); //Do not have an initial ffc on the clipboard.
24230 7 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
24231 7 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
24232 7 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
24233 7 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
24234 7 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
24235
24236 7 call_foo_dlg();
24237
24238 7 application_has_loaded = true;
24239
24240
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 while(!exiting_program)
24241 {
24242 handle_sentry_tags();
24243
24244 #ifdef _WIN32
24245 if(zqUseWin32Proc != FALSE)
24246 win32data.Update(Frameskip); //experimental win32 fixes
24247 #endif
24248 check_autosave();
24249 ++alignment_arrow_timer;
24250
24251 if(alignment_arrow_timer>63)
24252 {
24253 alignment_arrow_timer=0;
24254 }
24255 ++frame;
24256
24257 file_menu.disable_uid(MENUID_FILE_SAVE, saved||disable_saving||OverwriteProtection);
24258 file_menu.disable_uid(MENUID_FILE_REVERT, saved||disable_saving||OverwriteProtection);
24259 file_menu.disable_uid(MENUID_FILE_SAVEAS, disable_saving);
24260
24261 fixtools_menu.disable_uid(MENUID_FIXTOOL_OLDSTRING,
24262 !(get_qr(qr_OLD_STRING_EDITOR_MARGINS)
24263 ||get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT)));
24264
24265 edit_menu.disable_uid(MENUID_EDIT_UNDO, !Map.CanUndo());
24266 edit_menu.disable_uid(MENUID_EDIT_REDO, !Map.CanRedo());
24267
24268 bool canpaste = Map.CanPaste();
24269 edit_menu.disable_uid(MENUID_EDIT_PASTE, !canpaste);
24270 edit_menu.disable_uid(MENUID_EDIT_PASTEALL, !canpaste);
24271 edit_menu.disable_uid(MENUID_EDIT_ADVPASTE, !canpaste);
24272 edit_menu.disable_uid(MENUID_EDIT_SPECPASTE, !canpaste);
24273 rc_menu_screen.disable_uid(MENUID_RCSCREEN_PASTE, !canpaste);
24274 rc_menu_screen.disable_uid(MENUID_RCSCREEN_ADVPASTE, !canpaste);
24275 rc_menu_screen.disable_uid(MENUID_RCSCREEN_SPECPASTE, !canpaste);
24276 for(MenuItem& mit : paste_menu.inner())
24277 mit.disable(!canpaste);
24278 for(MenuItem& mit : paste_item_menu.inner())
24279 mit.disable(!canpaste);
24280
24281 edit_menu.disable_uid(MENUID_EDIT_COPY, !(Map.CurrScr()->valid&mVALID));
24282 edit_menu.disable_uid(MENUID_EDIT_DELETE, !(Map.CurrScr()->valid&mVALID));
24283
24284 // Are some things selected?
24285 view_menu.select_uid(MENUID_VIEW_WALKABILITY, Flags&cWALK);
24286 view_menu.select_uid(MENUID_VIEW_FLAGS, Flags&cFLAGS);
24287 view_menu.select_uid(MENUID_VIEW_CSET, Flags&cCSET);
24288 view_menu.select_uid(MENUID_VIEW_TYPES, Flags&cCTYPE);
24289 view_menu.select_uid(MENUID_VIEW_INFO, ShowInfo);
24290 view_menu.select_uid(MENUID_VIEW_SQUARES, ShowSquares);
24291 view_menu.select_uid(MENUID_VIEW_FFCS, ShowFFCs);
24292 view_menu.select_uid(MENUID_VIEW_SCRIPTNAMES, ShowFFScripts);
24293 view_menu.select_uid(MENUID_VIEW_GRID, ShowGrid);
24294 view_menu.select_uid(MENUID_VIEW_SCREENGRID, ShowScreenGrid);
24295 view_menu.select_uid(MENUID_VIEW_REGIONGRID, ShowRegionGrid);
24296 view_menu.select_uid(MENUID_VIEW_CURSCROUTLINE, ShowCurScreenOutline);
24297 view_menu.select_uid(MENUID_VIEW_DARKNESS, get_qr(qr_NEW_DARKROOM) && (Flags&cNEWDARK));
24298 view_menu.select_uid(MENUID_VIEW_L2BG, ViewLayer2BG);
24299 view_menu.select_uid(MENUID_VIEW_L3BG, ViewLayer3BG);
24300 view_menu.select_uid(MENUID_VIEW_LAYERHIGHLIGHT, ActiveLayerHighlight);
24301
24302 maps_menu.disable_uid(MENUID_MAPS_NEXT, !map_count || Map.getCurrMap() >= map_count);
24303 maps_menu.disable_uid(MENUID_MAPS_PREV, Map.getCurrMap()<=0);
24304
24305 etc_menu.disable_uid(MENUID_ETC_VIDMODE, isFullScreen()==1);
24306 etc_menu.select_uid(MENUID_ETC_FULLSCREEN, isFullScreen()==1);
24307
24308 if(!update_dialog(player2))
24309 exiting_program = true;
24310
24311 //clear_keybuf();
24312 handle_close_btn_quit();
24313 }
24314
24315 7 zq_exit(0);
24316 7 return 0;
24317 }
24318 END_OF_MAIN()
24319
24320 11 void zq_exit(int code)
24321 {
24322 11 set_is_exiting();
24323 11 parser_console.kill();
24324 11 killConsole();
24325
24326 11 quit_game();
24327 11 allegro_exit();
24328 11 exit(code);
24329 }
24330
24331 56 void init_bitmap(BITMAP** bmp, int32_t w, int32_t h)
24332 {
24333
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 56 times.
56 if(*bmp)
24334 destroy_bitmap(*bmp);
24335 56 *bmp = create_bitmap_ex(8,w,h);
24336 56 clear_bitmap(*bmp);
24337 56 }
24338 8 void load_size_poses()
24339 {
24340 8 ttip_uninstall_all();
24341
24342 8 FONT* favcmdfont = get_custom_font(CFONT_FAVCMD);
24343 8 FONT* guifont = get_custom_font(CFONT_GUI);
24344
24345 8 d_nbmenu_proc(MSG_START, &dialogs[0], 0);
24346
24347 8 commands_list.xscale = command_buttonwidth;
24348 8 commands_list.yscale = 10+text_height(favcmdfont);
24349
24350 8 auto drawmode_wid = 64;
24351
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 8 times.
56 for(auto q = 0; q < dm_max; ++q)
24352 {
24353 48 auto wid = text_length(guifont, dm_names[q]);
24354
1/2
✓ Branch 0 taken 48 times.
✗ Branch 1 not taken.
48 if(wid > drawmode_wid)
24355 drawmode_wid = wid;
24356 48 }
24357
24358 //Main GUI objects
24359
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(is_compact)
24360 {
24361 8 num_combo_cols = 2;
24362 8 combo_col_scale = 16;
24363
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_merged_combopane)
24364 {
24365 8 num_combo_cols = 1;
24366 8 combo_col_scale = 32;
24367 8 }
24368
24369 8 mapscreen_x=0;
24370 8 mapscreen_y=dialogs[0].h;
24371 8 mapscreen_screenunit_scale=3;
24372 8 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24373 8 showedges=0;
24374 8 showallpanels=0;
24375
24376 8 blackout_color=8;
24377
24378 8 auto mapscr_wid = (((showedges?2:0)+16)*16*mapscreen_screenunit_scale);
24379 8 combolist_window.w=zq_screen_w-mapscr_wid;
24380 8 combolist_window.x=zq_screen_w-combolist_window.w;
24381
24382 8 favorites_window.x=combolist_window.x;
24383 8 favorites_window.w=combolist_window.w;
24384 8 favorites_window.h=136;
24385 8 favorites_window.y=zq_screen_h-favorites_window.h;
24386
24387 8 combolist_window.y=0;
24388 8 combolist_window.h=favorites_window.y-combolist_window.y;
24389
24390 8 combo_preview.x=zq_screen_w-32-8;
24391 8 combo_preview.y=combolist_window.y+6;
24392 8 combo_preview.w=32;
24393 8 combo_preview.h=32;
24394 8 combo_preview2.clear();
24395
24396 8 auto col_wid = 4*combo_col_scale;
24397 8 auto cols_wid = col_wid * num_combo_cols;
24398 8 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24399
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 8 times.
16 for(auto q = 0; q < num_combo_cols; ++q)
24400 {
24401 8 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24402 8 combolist[q].y=combolist_window.y+54;
24403 8 combolist[q].w=4;
24404 8 combolist[q].h=compact_merged_combopane ? 15 : 30;
24405 8 combolist[q].xscale = combo_col_scale;
24406 8 combolist[q].yscale = combo_col_scale;
24407
24408 8 comboaliaslist[q].x = combolist[q].x;
24409 8 comboaliaslist[q].y = combolist[q].y;
24410 8 comboaliaslist[q].w = 4;
24411 8 comboaliaslist[q].h = compact_merged_combopane ? 13 : 26;
24412 8 comboaliaslist[q].xscale = combo_col_scale;
24413 8 comboaliaslist[q].yscale = combo_col_scale;
24414
24415 8 combolistscrollers[q].w=2;
24416 8 combolistscrollers[q].h=1;
24417 8 combolistscrollers[q].xscale=11;
24418 8 combolistscrollers[q].yscale=11;
24419 8 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24420 8 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-3;
24421 8 }
24422
24423 8 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24424 8 comboalias_preview.h=64;
24425 8 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24426 8 comboalias_preview.w=64;
24427
24428 8 combo_merge_btn.w = 20;
24429 8 combo_merge_btn.h = 20;
24430 8 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24431 8 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24432
24433
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(num_combo_cols == 1)
24434 {
24435 8 combolistscrollers[0].x += 34;
24436 8 }
24437 8 drawmode_btn.x = combolist_window.x-drawmode_wid;
24438 8 drawmode_btn.y = 0;
24439 8 drawmode_btn.w = drawmode_wid;
24440 8 drawmode_btn.h = mapscreen_y;
24441
24442 8 compactbtn.w = text_length(guifont,"> Compact")+10;
24443 8 compactbtn.x = drawmode_btn.x-compactbtn.w;
24444 8 compactbtn.y = drawmode_btn.y;
24445 8 compactbtn.h = drawmode_btn.h;
24446
24447 8 zoominbtn.w = text_length(guifont,"+")+10;
24448 8 zoominbtn.x = compactbtn.x-zoominbtn.w;
24449 8 zoominbtn.y = compactbtn.y;
24450 8 zoominbtn.h = compactbtn.h;
24451
24452 8 zoomoutbtn.w = text_length(guifont,"-")+10;
24453 8 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24454 8 zoomoutbtn.y = compactbtn.y;
24455 8 zoomoutbtn.h = compactbtn.h;
24456
24457
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 8 times.
80 for(int32_t i=0; i<=8; i++)
24458 {
24459 72 map_page_bar[i].w = 48;
24460 72 map_page_bar[i].x = mapscreen_x+(i*48);
24461 72 map_page_bar[i].y = mapscreen_y+(11*16*mapscreen_screenunit_scale);
24462 72 map_page_bar[i].h = text_height(guifont)+12;
24463 72 }
24464
24465 8 minimap.w=7+48*3;
24466 8 minimap.h=16+27*3;
24467
24468 8 layer_panel.x=map_page_bar[6].x;
24469 8 layer_panel.y=map_page_bar[0].y;
24470 8 layer_panel.w=combolist_window.x - layer_panel.x;
24471 8 layer_panel.h=map_page_bar[0].h;
24472 8 layerpanel_buttonwidth = 51;
24473 8 layerpanel_buttonheight = layer_panel.h;
24474 8 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24475 8 layerpanel_checkbox_wid = 15;
24476
24477 8 minimap.x=3;
24478 8 minimap.y=layer_panel.y+layer_panel.h+4;
24479
24480 8 real_minimap.x = minimap.x+3;
24481 8 real_minimap.y = minimap.y+5;
24482 8 real_minimap.w = 16;
24483 8 real_minimap.h = 9;
24484 8 real_minimap.xscale = 9;
24485 8 real_minimap.yscale = 9;
24486 8 real_minimap.fw = real_minimap.xscale*8;
24487 8 real_minimap.fh = real_minimap.yscale*8;
24488
24489 8 int upscale_mm = 3;
24490 8 int xwid = real_minimap.tw()*(upscale_mm-1);
24491 8 int xhei = real_minimap.th()*(upscale_mm-1);
24492 8 minimap_zoomed.set(minimap.x, minimap.y-xhei, minimap.w+xwid, minimap.h+xhei+4);
24493 8 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24494 8 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24495 8 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24496
24497 8 screrrorpos.x = combolist_window.x - 3;
24498 8 screrrorpos.y = layer_panel.y - 16;
24499
24500 8 mouse_scroll_h=10;
24501
24502 8 favorites_list.x=favorites_window.x+8;
24503 8 favorites_list.y=favorites_window.y+16;
24504 8 favorites_list.xscale = 16;
24505 8 favorites_list.yscale = 16;
24506 8 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24507 8 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24508
24509 8 commands_list.w=4;
24510
24511 8 int bh = commands_list.yscale;
24512 8 int bw = 26;
24513 8 commands_window.w=commands_list.w*commands_list.xscale+10+bw;
24514 8 commands_window.x=combolist_window.x-commands_window.w;
24515 8 commands_window.y=layer_panel.y+layer_panel.h;
24516 8 commands_window.h=zq_screen_h-commands_window.y;
24517 8 int bx = commands_window.x+2;
24518
24519 8 commands_list.y=commands_window.y+4;
24520 8 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24521 8 commands_list.x=bx+bw;
24522
24523 8 commands_zoombtn.w = bw;
24524 8 commands_zoombtn.h = bh;
24525 8 commands_zoombtn.x = bx;
24526 8 commands_zoombtn.y = commands_list.y;
24527
24528 8 commands_infobtn.w = bw;
24529 8 commands_infobtn.h = bh;
24530 8 commands_infobtn.x = bx;
24531 8 commands_infobtn.y = commands_zoombtn.y + commands_infobtn.h;
24532
24533 8 commands_x.w = bw;
24534 8 commands_x.h = bh;
24535 8 commands_x.x = bx;
24536 8 commands_x.y = commands_infobtn.y + commands_x.h;
24537
24538 8 commands_txt.clear();
24539
24540 8 main_panel.x = 0;
24541 8 main_panel.y = layer_panel.y+layer_panel.h;
24542 8 main_panel.w = commands_window.x - main_panel.x;
24543 8 main_panel.h = 76+32;
24544 8 preview_panel = main_panel;
24545 8 preview_panel.x = 0;
24546 8 preview_panel.w = commands_window.x - preview_panel.x;
24547
24548 8 preview_text.x = preview_panel.x+3;
24549 8 preview_text.y = preview_panel.y+3;
24550 8 preview_text.w = 2;
24551 8 preview_text.h = 6;
24552 8 preview_text.xscale = 10;
24553 8 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24554
24555 8 panel_align = 1;
24556 8 int swapbtnw = 32, swapbtnh = 20;
24557 8 int swapbtnx = main_panel.x+main_panel.tw()-swapbtnw;
24558 8 squarepanel_swap_btn.set(swapbtnx, zq_screen_h-swapbtnh, swapbtnw, swapbtnh);
24559
24560 8 int sqx = minimap.x+minimap.tw();
24561 8 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24562
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(compact_square_panels)
24563 {
24564 int cmpy = main_panel.y+(main_panel.th()/2);
24565 squarepanel_up_btn.set(swapbtnx, cmpy-swapbtnh, swapbtnw, swapbtnh);
24566 squarepanel_down_btn.set(swapbtnx, cmpy, swapbtnw, swapbtnh);
24567
24568 txtoffs_single.x = 18;
24569 txtoffs_single.y = 36;
24570 txtoffs_double_1.x = 18;
24571 txtoffs_double_1.y = 36;
24572 txtoffs_double_2.x = 18;
24573 txtoffs_double_2.y = 36 + text_height(get_custom_font(CFONT_GUI));
24574
24575 //Clear them all- if they stay cleared, they are invisible.
24576 itemsqr_pos.clear();
24577 stairsqr_pos.clear();
24578 warparrival_pos.clear();
24579 flagsqr_pos.clear();
24580 enemy_prev_pos.clear();
24581 for(int q = 0; q < 4; ++q)
24582 warpret_pos[q].clear();
24583
24584 int sqr_x1 = sqx+12;
24585 int sqr_y1 = main_panel.y+12;
24586 int sqr_xoffs = (16*2)+4 + 12;
24587 switch(compact_active_panel)
24588 {
24589 case 0: //Warp Squares
24590 {
24591 int x = sqr_x1;
24592 for(int q = 0; q < 4; ++q)
24593 {
24594 warpret_pos[q].set(x,sqr_y1,(16*2)+4,(16*2)+4);
24595 x += sqr_xoffs;
24596 }
24597 break;
24598 }
24599 case 1: //Other Squares
24600 {
24601 itemsqr_pos.set(sqr_x1+(sqr_xoffs*0), sqr_y1, (16*2)+4,(16*2)+4);
24602 stairsqr_pos.set(sqr_x1+(sqr_xoffs*1), sqr_y1, (16*2)+4,(16*2)+4);
24603 warparrival_pos.set(sqr_x1+(sqr_xoffs*2), sqr_y1, (16*2)+4,(16*2)+4);
24604 flagsqr_pos.set(sqr_x1+(sqr_xoffs*3), sqr_y1, (16*2)+4,(16*2)+4);
24605 break;
24606 }
24607 case 2: //Enemy Preview
24608 {
24609 enemy_prev_pos.set(sqr_x1, sqr_y1, 5, 2, 32, 32);
24610 break;
24611 }
24612 }
24613 }
24614 else
24615 {
24616 8 squarepanel_up_btn.clear();
24617 8 squarepanel_down_btn.clear();
24618 8 txtoffs_single.x = 10;
24619 8 txtoffs_single.y = 22;
24620 8 txtoffs_double_1.x = 10;
24621 8 txtoffs_double_1.y = 22;
24622 8 txtoffs_double_2.x = 10;
24623 8 txtoffs_double_2.y = 30;
24624
24625
24626 8 int sqr_x1 = sqx+24;
24627 8 int sqr_y1 = main_panel.y+12;
24628 8 int sqr_y2 = sqr_y1+42;
24629 8 int sqr_xdist = 32;
24630 8 itemsqr_pos.set(sqr_x1+(sqr_xdist*0),sqr_y1,20,20);
24631 8 stairsqr_pos.set(sqr_x1+(sqr_xdist*1),sqr_y1,20,20);
24632 8 warparrival_pos.set(sqr_x1+(sqr_xdist*2),sqr_y1,20,20);
24633 8 flagsqr_pos.set(sqr_x1+(sqr_xdist*3),sqr_y1,20,20);
24634
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 8 times.
40 for(auto q = 0; q < 4; ++q)
24635 {
24636 32 warpret_pos[q].set(sqr_x1+(sqr_xdist*q),sqr_y2,20,20);
24637 32 }
24638 8 enemy_prev_pos.set(sqr_x1+(sqr_xdist*4), sqr_y1, 4, 3, 16, 16);
24639 8 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24640 8 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24641 }
24642
24643 8 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24644 8 combopool_preview.x=comboaliaslist[0].x;
24645 8 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24646 8 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24647 8 combopool_preview.h=zq_screen_h-8-combopool_preview.y;
24648 8 combopool_preview.w -= combopool_preview.w%16;
24649 8 combopool_preview.h -= combopool_preview.h%16;
24650
24651 8 FONT* tfont = get_zc_font(font_lfont_l);
24652 8 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24653 8 combopool_prevbtn.h = 11;
24654 8 combopool_prevbtn.x = combopool_preview.x;
24655 8 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24656
24657 8 mappage_count = 6;
24658
24659 8 txfont = get_zc_font(font_lfont_l);
24660 8 combo_preview_text1.set(combo_preview.x-5,combo_preview.y,1,3,1,text_height(txfont));
24661 8 combo_preview_text2.clear();
24662
24663 8 favorites_x.w = 17;
24664 8 favorites_infobtn.w = 17;
24665 8 favorites_zoombtn.w = 17;
24666 8 favorites_pgleft.w = 17;
24667 8 favorites_pgright.w = 17;
24668 8 }
24669 else
24670 {
24671 num_combo_cols = 4;
24672 combo_col_scale = 16;
24673 if(large_merged_combopane)
24674 {
24675 num_combo_cols = 2;
24676 combo_col_scale = 32;
24677 }
24678
24679 mapscreen_x=0;
24680 mapscreen_y=dialogs[0].h;
24681 mapscreen_screenunit_scale=2;
24682 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24683 showedges=Map.getViewSize() <= 2 ? 1 : 0;
24684 showallpanels=0;
24685
24686 blackout_color=8;
24687
24688 favorites_window.h=136;
24689 favorites_window.y=zq_screen_h-favorites_window.h;
24690
24691 auto mapscr_wid = (((2)+16)*16*mapscreen_screenunit_scale);
24692 combolist_window.w=zq_screen_w-mapscr_wid;
24693 combolist_window.x=zq_screen_w-combolist_window.w;
24694 combolist_window.y=0;
24695 combolist_window.h=favorites_window.y-combolist_window.y;
24696
24697 favorites_window.x=combolist_window.x;
24698 favorites_window.w=combolist_window.w;
24699
24700 combo_preview.x=(zq_screen_w-(combolist_window.w/2))-40;
24701 combo_preview.y=combolist_window.y+6;
24702 combo_preview.w=32;
24703 combo_preview.h=32;
24704 combo_preview2 = combo_preview;
24705 combo_preview2.x += 48;
24706
24707 auto col_wid = 4*combo_col_scale;
24708 auto cols_wid = col_wid * num_combo_cols;
24709 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24710 for(auto q = 0; q < num_combo_cols; ++q)
24711 {
24712 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24713 combolist[q].y=combolist_window.y+60;
24714 combolist[q].w=4;
24715 combolist[q].h=large_merged_combopane ? 15 : 30;
24716 combolist[q].xscale = combo_col_scale;
24717 combolist[q].yscale = combo_col_scale;
24718
24719 comboaliaslist[q].x=combolist[q].x;
24720 comboaliaslist[q].y=combolist[q].y;
24721 comboaliaslist[q].w=4;
24722 comboaliaslist[q].h=large_merged_combopane ? 12 : 25;
24723 comboaliaslist[q].xscale = combo_col_scale;
24724 comboaliaslist[q].yscale = combo_col_scale;
24725
24726 combolistscrollers[q].w=2;
24727 combolistscrollers[q].h=1;
24728 combolistscrollers[q].xscale=11;
24729 combolistscrollers[q].yscale=11;
24730 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24731 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-2;
24732 }
24733
24734 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24735 comboalias_preview.h=64;
24736 comboalias_preview.w=64;
24737 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24738
24739 combo_merge_btn.w = 20;
24740 combo_merge_btn.h = 20;
24741 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24742 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24743 squarepanel_swap_btn.clear();
24744 squarepanel_up_btn.clear();
24745 squarepanel_down_btn.clear();
24746
24747 drawmode_btn.x = combolist_window.x-drawmode_wid;
24748 drawmode_btn.y = 0;
24749 drawmode_btn.w = drawmode_wid;
24750 drawmode_btn.h = mapscreen_y;
24751
24752 compactbtn.w = text_length(guifont,"> Compact")+10;
24753 compactbtn.x = drawmode_btn.x-compactbtn.w;
24754 compactbtn.y = drawmode_btn.y;
24755 compactbtn.h = drawmode_btn.h;
24756
24757 zoominbtn.w = text_length(guifont,"+")+10;
24758 zoominbtn.x = compactbtn.x-zoominbtn.w;
24759 zoominbtn.y = compactbtn.y;
24760 zoominbtn.h = compactbtn.h;
24761
24762 zoomoutbtn.w = text_length(guifont,"-")+10;
24763 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24764 zoomoutbtn.y = compactbtn.y;
24765 zoomoutbtn.h = compactbtn.h;
24766
24767 for(int32_t i=0; i<=8; i++)
24768 {
24769 map_page_bar[i].x = mapscreen_x+(i*16*2*mapscreen_screenunit_scale);
24770 map_page_bar[i].y = mapscreen_y+((13)*16*mapscreen_screenunit_scale);
24771 map_page_bar[i].w = 64;
24772 map_page_bar[i].h = text_height(guifont)+12;
24773 }
24774
24775 minimap.w=7+48*3;
24776 minimap.h=16+27*3;
24777
24778 layer_panel.x=map_page_bar[0].x;
24779 layer_panel.y=map_page_bar[0].y+map_page_bar[0].h;
24780 layer_panel.w=map_page_bar[8].x+map_page_bar[8].w;
24781 layer_panel.h=text_height(guifont)+8;
24782 layerpanel_buttonwidth = 58;
24783 layerpanel_buttonheight = layer_panel.h;
24784 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24785 layerpanel_checkbox_wid = 14;
24786
24787 commands_list.w=4;
24788 commands_window.w=commands_list.w*commands_list.xscale+16;
24789 commands_window.x=combolist_window.x-commands_window.w;
24790 commands_window.y=layer_panel.y+layer_panel.h;
24791 commands_window.h=zq_screen_h-commands_window.y;
24792
24793 //buttons panel
24794 main_panel.x = 0;
24795 main_panel.y = layer_panel.y+layer_panel.h;
24796 main_panel.w = commands_window.x - main_panel.x;
24797 main_panel.h = zq_screen_h - main_panel.y;
24798 preview_panel = main_panel;
24799
24800 preview_text.x = preview_panel.x+3;
24801 preview_text.y = preview_panel.y+3;
24802 preview_text.w = 1;
24803 preview_text.h = 12;
24804 preview_text.xscale = 10;
24805 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
24806
24807 minimap.x=3;
24808 minimap.y=main_panel.y+4;
24809
24810 real_minimap.x = minimap.x+3;
24811 real_minimap.y = minimap.y+5;
24812 real_minimap.w = 16;
24813 real_minimap.h = 9;
24814 real_minimap.xscale = 9;
24815 real_minimap.yscale = 9;
24816 real_minimap.fw = real_minimap.xscale*8;
24817 real_minimap.fh = real_minimap.yscale*8;
24818
24819 int upscale_mm = 4;
24820 int xwid = real_minimap.tw()*(upscale_mm-1);
24821 int xhei = real_minimap.th()*(upscale_mm-1);
24822 int zh = minimap.h+xhei+4;
24823 minimap_zoomed.set(minimap.x, zq_screen_h-zh, minimap.w+xwid, zh);
24824 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24825 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24826 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24827
24828 screrrorpos.x = 575;
24829 screrrorpos.y = 388;
24830
24831 mouse_scroll_h=10;
24832
24833 favorites_list.x=favorites_window.x+8;
24834 favorites_list.y=favorites_window.y+16;
24835 favorites_list.xscale = 16;
24836 favorites_list.yscale = 16;
24837 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24838 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24839
24840 int bh = 16;
24841 int by = commands_window.y+4;
24842 commands_list.y=by+bh;
24843 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24844 commands_list.x=commands_window.x+8;
24845
24846 commands_x.w = 20;
24847 commands_x.h = bh;
24848 commands_x.x = commands_list.x + commands_list.tw() - commands_x.w;
24849 commands_x.y = by;
24850
24851 commands_infobtn.w = 20;
24852 commands_infobtn.h = bh;
24853 commands_infobtn.x = commands_x.x - commands_infobtn.w;
24854 commands_infobtn.y = by;
24855
24856 commands_zoombtn.w = 20;
24857 commands_zoombtn.h = bh;
24858 commands_zoombtn.x = commands_infobtn.x - commands_zoombtn.w;
24859 commands_zoombtn.y = by;
24860
24861 commands_txt.x = commands_list.x;
24862 commands_txt.y = by+(bh-text_height(get_zc_font(font_lfont_l)))/2;
24863
24864 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24865 favorites_x.y = favorites_list.y-15;
24866
24867 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24868 favorites_infobtn.y = favorites_x.y;
24869
24870 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24871 favorites_zoombtn.y = favorites_infobtn.y;
24872
24873 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24874 favorites_pgright.y = favorites_zoombtn.y;
24875
24876 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24877 favorites_pgleft.y = favorites_pgleft.y;
24878
24879 txtoffs_single.x = 22;
24880 txtoffs_single.y = 6;
24881 txtoffs_double_1.x = 22;
24882 txtoffs_double_1.y = 2;
24883 txtoffs_double_2.x = 22;
24884 txtoffs_double_2.y = 10;
24885 panel_align = 0;
24886
24887 int sqx = minimap.x+minimap.tw();
24888 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
24889 int x2 = sqx+4;
24890 int x1 = x2 - (20+(8*3)+2);
24891 int y1 = main_panel.y+10;
24892 int sw = 20, sh = 20;
24893 int offs = sh+4;
24894
24895 itemsqr_pos.set(x2,y1+(0*offs),sw,sh);
24896 flagsqr_pos.set(x2,y1+(1*offs),sw,sh);
24897 stairsqr_pos.set(x2,y1+(2*offs),sw,sh);
24898 warparrival_pos.set(x2,y1+(6*offs),sw,sh);
24899
24900 enemy_prev_pos.x = main_panel.x+14;
24901 enemy_prev_pos.y = main_panel.y+12 + minimap.h;
24902 enemy_prev_pos.w = 4;
24903 enemy_prev_pos.h = 3;
24904 enemy_prev_pos.xscale = 16;
24905 enemy_prev_pos.yscale = 16;
24906 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
24907 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
24908
24909 warpret_pos[0].set(x1,y1+(4*offs),sw,sh);
24910 warpret_pos[1].set(x1,y1+(5*offs),sw,sh);
24911 warpret_pos[2].set(x2,y1+(4*offs),sw,sh);
24912 warpret_pos[3].set(x2,y1+(5*offs),sw,sh);
24913
24914 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
24915 combopool_preview.x=comboaliaslist[0].x;
24916 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
24917 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
24918 combopool_preview.h=(favorites_window.y-combopool_preview.y);//+favorites_window.h-10;
24919 combopool_preview.w -= combopool_preview.w%16;
24920 combopool_preview.h -= combopool_preview.h%16;
24921
24922 FONT* tfont = get_zc_font(font_lfont_l);
24923 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
24924 combopool_prevbtn.h = 11;
24925 combopool_prevbtn.x = combopool_preview.x;
24926 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
24927
24928 mappage_count = 9;
24929
24930 txfont = get_zc_font(font_lfont_l);
24931 combo_preview_text1.set(combo_preview.x-9,combo_preview.y,1,3,1,text_height(txfont));
24932 combo_preview_text2.set(combo_preview2.x+combo_preview2.w+8,combo_preview2.y,1,3,1,text_height(txfont));
24933
24934 favorites_x.w = 30;
24935 favorites_infobtn.w = 30;
24936 favorites_zoombtn.w = 30;
24937 favorites_pgleft.w = 30;
24938 favorites_pgright.w = 30;
24939 }
24940 //Same in all modes
24941 {
24942
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_cmd : large_zoomed_cmd)
24943 {
24944 8 commands_list.w /= 2;
24945 8 commands_list.xscale *= 2;
24946 8 }
24947
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8 times.
8 if(is_compact ? compact_zoomed_fav : large_zoomed_fav)
24948 {
24949
1/2
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
8 if(favorites_list.w%2)
24950 favorites_list.x += (favorites_list.xscale / 2);
24951 8 favorites_list.xscale *= 2;
24952 8 favorites_list.yscale *= 2;
24953 8 favorites_list.w /= 2;
24954 8 favorites_list.h /= 2;
24955 8 }
24956
24957 8 favorites_x.h = 14;
24958 8 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
24959 8 favorites_x.y = favorites_list.y-15;
24960
24961 8 favorites_infobtn.h = favorites_x.h;
24962 8 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
24963 8 favorites_infobtn.y = favorites_x.y;
24964
24965 8 favorites_zoombtn.h = favorites_infobtn.h;
24966 8 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
24967 8 favorites_zoombtn.y = favorites_infobtn.y;
24968
24969 8 favorites_pgright.h = favorites_zoombtn.h;
24970 8 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
24971 8 favorites_pgright.y = favorites_zoombtn.y;
24972
24973 8 favorites_pgleft.h = favorites_pgright.h;
24974 8 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
24975 8 favorites_pgleft.y = favorites_pgright.y;
24976
24977 8 mainbar.x = dialogs[0].x+dialogs[0].w;
24978 8 mainbar.y = 0;
24979 8 mainbar.w = zoomoutbtn.x-mainbar.x;
24980 8 mainbar.h = drawmode_btn.h;
24981 }
24982
24983 //Ensure current combo list selected is valid
24984 8 current_combolist=vbound(current_combolist,0,num_combo_cols-1);
24985 8 current_comboalist=vbound(current_comboalist,0,num_combo_cols-1);
24986 8 current_cpoollist=vbound(current_cpoollist,0,num_combo_cols-1);
24987 8 current_cautolist = vbound(current_cautolist, 0, num_combo_cols - 1);
24988
24989 //Generate bitmaps
24990 8 init_bitmap(&mapscreenbmp,16*(showedges?18:16),16*(showedges?13:11));
24991 8 init_bitmap(&brushbmp,256*mapscreen_screenunit_scale,176*mapscreen_screenunit_scale);
24992 8 init_bitmap(&brushscreen,(256+(showedges?16:0))*mapscreen_screenunit_scale,(176+(showedges?16:0))*mapscreen_screenunit_scale);
24993
24994 8 init_bitmap(&screen2,zq_screen_w,zq_screen_h);
24995 8 init_bitmap(&tmp_scr,zq_screen_w,zq_screen_h);
24996 8 init_bitmap(&menu1,zq_screen_w,zq_screen_h);
24997 8 init_bitmap(&menu3,zq_screen_w,zq_screen_h);
24998
24999 8 center_zq_class_dialogs();
25000 8 center_zq_custom_dialogs();
25001 8 center_zq_files_dialogs();
25002 8 center_zq_subscreen_dialogs();
25003 8 center_zq_tiles_dialogs();
25004 8 center_zquest_dialogs();
25005
25006 8 aspect_ratio = zq_screen_h / double(zq_screen_w);
25007
25008 8 mmap_init();
25009 8 }
25010
25011 11 void remove_locked_params_on_exit()
25012 {
25013 11 al_trace("Removing timers. \n");
25014 11 remove_int(fps_callback);
25015 11 remove_int(dclick_check);
25016 11 }
25017
25018 11 void destroy_bitmaps_on_exit()
25019 {
25020 11 al_trace("Cleaning bitmaps...");
25021 11 destroy_bitmap(screen2);
25022 11 destroy_bitmap(tmp_scr);
25023 11 destroy_bitmap(menu1);
25024 11 destroy_bitmap(menu3);
25025 11 destroy_bitmap(mapscreenbmp);
25026 11 destroy_bitmap(dmapbmp_small);
25027 11 destroy_bitmap(dmapbmp_large);
25028 11 destroy_bitmap(brushbmp);
25029 11 destroy_bitmap(brushscreen);
25030 11 al_trace("...");
25031
25032
2/2
✓ Branch 0 taken 528 times.
✓ Branch 1 taken 11 times.
539 for(int32_t i=0; i<MOUSE_BMP_MAX*4; i++)
25033 {
25034 528 destroy_bitmap(mouse_bmp[i/4][i%4]);
25035 528 destroy_bitmap(mouse_bmp_1x[i/4][i%4]);
25036 528 }
25037
25038
2/2
✓ Branch 0 taken 352 times.
✓ Branch 1 taken 11 times.
363 for(int32_t i=0; i<ICON_BMP_MAX*4; i++)
25039 352 destroy_bitmap(icon_bmp[i/4][i%4]);
25040
25041
2/2
✓ Branch 0 taken 704 times.
✓ Branch 1 taken 11 times.
715 for(int32_t i=0; i<16*4; i++)
25042 704 destroy_bitmap(flag_bmp[i/4][i%4]);
25043
2/2
✓ Branch 0 taken 22 times.
✓ Branch 1 taken 11 times.
33 for(int32_t i=0; i<2; i++)
25044 22 destroy_bitmap(select_bmp[i]);
25045
25046
2/2
✓ Branch 0 taken 88 times.
✓ Branch 1 taken 11 times.
99 for(int32_t i=0; i<MAXARROWS; i++)
25047 88 destroy_bitmap(arrow_bmp[i]);
25048
25049 11 al_trace(" OK. \n");
25050 11 }
25051
25052
25053 11 void quit_game()
25054 {
25055 11 set_last_timed_save(nullptr);
25056 11 save_config_file();
25057 11 zc_set_palette(black_palette);
25058 11 zc_stop_midi();
25059
25060 11 remove_locked_params_on_exit();
25061
25062 11 al_trace("Cleaning sfx. \n");
25063
25064
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<WAV_COUNT; i++)
25065 {
25066
2/2
✓ Branch 0 taken 2805 times.
✓ Branch 1 taken 11 times.
2816 if(customsfxdata[i].data!=NULL)
25067 {
25068 // delete [] customsfxdata[i].data;
25069 2805 free(customsfxdata[i].data);
25070 2805 }
25071
25072
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] sfx_string[i];
25073 2816 }
25074
25075
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXWPNS; i++)
25076 {
25077
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] weapon_string[i];
25078 2816 }
25079
25080
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXITEMS; i++)
25081 {
25082
1/2
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
2816 delete [] item_string[i];
25083 2816 }
25084
25085
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<eMAXGUYS; i++)
25086 {
25087
1/2
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
5632 delete [] guy_string[i];
25088 5632 }
25089
25090 11 al_trace("Cleaning script buffer. \n");
25091
25092
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25093 {
25094
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(ffscripts[i]!=NULL) delete ffscripts[i];
25095 5632 }
25096
25097
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25098 {
25099
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemscripts[i]!=NULL) delete itemscripts[i];
25100 2816 }
25101
25102
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25103 {
25104
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(guyscripts[i]!=NULL) delete guyscripts[i];
25105 2816 }
25106
25107
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25108 {
25109
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25110 2816 }
25111
25112
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25113 {
25114
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25115 2816 }
25116
25117
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25118 {
25119
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(screenscripts[i]!=NULL) delete screenscripts[i];
25120 2816 }
25121
25122
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 11 times.
44 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25123 {
25124
2/4
✓ Branch 0 taken 33 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 33 times.
33 if(globalscripts[i]!=NULL) delete globalscripts[i];
25125 33 }
25126
25127
2/2
✓ Branch 0 taken 55 times.
✓ Branch 1 taken 11 times.
66 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25128 {
25129
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 55 times.
55 if(playerscripts[i]!=NULL) delete playerscripts[i];
25130 55 }
25131
25132
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25133 {
25134
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25135 2816 }
25136
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25137 {
25138
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25139 2816 }
25140
2/2
✓ Branch 0 taken 5632 times.
✓ Branch 1 taken 11 times.
5643 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25141 {
25142
2/4
✓ Branch 0 taken 5632 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 5632 times.
5632 if(comboscripts[i]!=NULL) delete comboscripts[i];
25143 5632 }
25144
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2816 times.
2827 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25145 {
25146
2/4
✓ Branch 0 taken 2816 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2816 times.
2816 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25147 2816 }
25148
25149 11 al_trace("Cleaning qst buffers. \n");
25150 11 del_qst_buffers();
25151
25152
25153 11 al_trace("Cleaning midis. \n");
25154
25155
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(customtunes)
25156 {
25157
2/2
✓ Branch 0 taken 2816 times.
✓ Branch 1 taken 11 times.
2827 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25158 2816 customtunes[i].reset();
25159
25160 11 free(customtunes);
25161 11 }
25162
25163 11 al_trace("Cleaning undotilebuf. \n");
25164
25165 11 undocombobuf.clear();
25166
25167
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 3 times.
11 if(newundotilebuf)
25168 {
25169
2/2
✓ Branch 0 taken 1716000 times.
✓ Branch 1 taken 8 times.
1716008 for(int32_t i=0; i<NEWMAXTILES; i++)
25170
1/2
✓ Branch 0 taken 1716000 times.
✗ Branch 1 not taken.
1716000 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25171
25172 8 free(newundotilebuf);
25173 8 }
25174
25175
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(filepath) free(filepath);
25176
25177
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(datapath) free(datapath);
25178
25179
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(midipath) free(midipath);
25180
25181
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(imagepath) free(imagepath);
25182
25183
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(tmusicpath) free(tmusicpath);
25184
25185
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if(last_timed_save) free(last_timed_save);
25186
25187 11 destroy_bitmaps_on_exit();
25188 11 }
25189
25190 void quit_game2()
25191 {
25192 set_last_timed_save(nullptr);
25193 save_config_file();
25194 zc_set_palette(black_palette);
25195 zc_stop_midi();
25196
25197 remove_locked_params_on_exit();
25198
25199 al_trace("Cleaning sfx. \n");
25200
25201 for(int32_t i=0; i<WAV_COUNT; i++)
25202 {
25203 if(customsfxdata[i].data!=NULL)
25204 {
25205 // delete [] customsfxdata[i].data;
25206 free(customsfxdata[i].data);
25207 }
25208
25209 delete [] sfx_string[i];
25210 }
25211
25212 for(int32_t i=0; i<MAXWPNS; i++)
25213 {
25214 delete [] weapon_string[i];
25215 }
25216
25217 for(int32_t i=0; i<MAXITEMS; i++)
25218 {
25219 delete [] item_string[i];
25220 }
25221
25222 for(int32_t i=0; i<eMAXGUYS; i++)
25223 {
25224 delete [] guy_string[i];
25225 }
25226
25227 al_trace("Cleaning script buffer. \n");
25228
25229 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25230 {
25231 if(ffscripts[i]!=NULL) delete ffscripts[i];
25232 }
25233
25234 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25235 {
25236 if(itemscripts[i]!=NULL) delete itemscripts[i];
25237 }
25238
25239 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25240 {
25241 if(guyscripts[i]!=NULL) delete guyscripts[i];
25242 }
25243
25244 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25245 {
25246 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25247 }
25248
25249 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25250 {
25251 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25252 }
25253
25254 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25255 {
25256 if(screenscripts[i]!=NULL) delete screenscripts[i];
25257 }
25258
25259 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25260 {
25261 if(globalscripts[i]!=NULL) delete globalscripts[i];
25262 }
25263
25264 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25265 {
25266 if(playerscripts[i]!=NULL) delete playerscripts[i];
25267 }
25268
25269 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25270 {
25271 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25272 }
25273 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25274 {
25275 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25276 }
25277 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25278 {
25279 if(comboscripts[i]!=NULL) delete comboscripts[i];
25280 }
25281 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25282 {
25283 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25284 }
25285
25286 al_trace("Cleaning qst buffers. \n");
25287 del_qst_buffers();
25288
25289
25290 al_trace("Cleaning midis. \n");
25291
25292 if(customtunes)
25293 {
25294 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25295 customtunes[i].reset();
25296
25297 free(customtunes);
25298 }
25299
25300 al_trace("Cleaning undotilebuf. \n");
25301
25302 undocombobuf.clear();
25303
25304 if(newundotilebuf)
25305 {
25306 for(int32_t i=0; i<NEWMAXTILES; i++)
25307 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25308
25309 free(newundotilebuf);
25310 }
25311
25312 if(filepath) free(filepath);
25313
25314 if(datapath) free(datapath);
25315
25316 if(midipath) free(midipath);
25317
25318 if(imagepath) free(imagepath);
25319
25320 if(tmusicpath) free(tmusicpath);
25321
25322 if(last_timed_save) free(last_timed_save);
25323 }
25324
25325 8 void center_zquest_dialogs()
25326 {
25327 8 jwin_center_dialog(assignscript_dlg);
25328 8 jwin_center_dialog(autolayer_dlg);
25329 8 center_zq_cset_dialogs();
25330 8 jwin_center_dialog(change_track_dlg);
25331 8 jwin_center_dialog(csetfix_dlg);
25332 8 jwin_center_dialog(dmapmaps_dlg);
25333 8 center_zq_door_dialogs();
25334 8 jwin_center_dialog(editcomboa_dlg);
25335 8 jwin_center_dialog(editinfo_dlg);
25336 8 jwin_center_dialog(editmusic_dlg);
25337 8 jwin_center_dialog(editshop_dlg);
25338 8 jwin_center_dialog(ffcombo_sel_dlg);
25339 8 jwin_center_dialog(getnum_dlg);
25340 8 jwin_center_dialog(layerdata_dlg);
25341 8 jwin_center_dialog(list_dlg);
25342 8 jwin_center_dialog(loadmap_dlg);
25343 8 jwin_center_dialog(misccolors_dlg);
25344 8 jwin_center_dialog(newcomboa_dlg);
25345 8 jwin_center_dialog(orgcomboa_dlg);
25346 8 jwin_center_dialog(path_dlg);
25347 8 jwin_center_dialog(screen_pal_dlg);
25348 8 jwin_center_dialog(secret_dlg);
25349 8 jwin_center_dialog(selectdmap_dlg);
25350 8 jwin_center_dialog(selectmusic_dlg);
25351 8 jwin_center_dialog(showpal_dlg);
25352 8 jwin_center_dialog(strlist_dlg);
25353 8 jwin_center_dialog(template_dlg);
25354 8 jwin_center_dialog(tp_dlg);
25355 8 jwin_center_dialog(under_dlg);
25356 8 jwin_center_dialog(tilewarp_dlg);
25357 8 jwin_center_dialog(sidewarp_dlg);
25358 8 jwin_center_dialog(warpring_dlg);
25359 8 center_zscript_dialogs();
25360 8 }
25361
25362
25363 void animate_coords()
25364 {
25365 coord_frame=(coord_timer>>3)&3;
25366
25367 if(++coord_timer>=(1<<5))
25368 {
25369 coord_timer=0;
25370 }
25371 }
25372
25373 static const char *help_list[] =
25374 {
25375 "PREVIEW MODE",
25376 "PgUp/PgDn - Scroll through hotkey list",
25377 "Esc/Enter - Exit Preview Mode",
25378 "R - Restore screen to original state",
25379 "C - Toggle combo cycling On/Off",
25380 "S - Trigger screen secrets",
25381 "Q/W/F - These still work",
25382 "P - Pause everything",
25383 "A - Advance frame-by-frame",
25384 "1-4 - Trigger tile warp A-D",
25385 "5-8 - Trigger side warp A-D",
25386 "9 - Enable timed warps",
25387 "",
25388 "",
25389 };
25390
25391 void do_previewtext()
25392 {
25393 FONT* oldfont = font;
25394 font = get_zc_font(font_lfont_l);
25395
25396 //Put in help areas
25397 auto& sqr = preview_text;
25398 int ind = 0, len = 0;
25399 for(int q = 0; q < 12; ++q)
25400 {
25401 int l = text_length(font, help_list[q]);
25402 if(len < l) len = l;
25403 }
25404 sqr.xscale = len+2;
25405 sqr.yscale = text_height(font);
25406 for(int col = 0; col < sqr.w; ++col)
25407 {
25408 for(int row = 0; row < sqr.h; ++row)
25409 {
25410 auto& line = sqr.subsquare(col,row);
25411 textprintf_ex(menu1,font,line.x,line.y,jwin_pal[jcTEXTFG],-1,"%s",help_list[ind++]);
25412 }
25413 }
25414
25415 font = oldfont;
25416 }
25417
25418
25419 bool reload_fonts = false;
25420 void run_zq_frame()
25421 {
25422 if(reload_fonts)
25423 {
25424 init_custom_fonts();
25425 load_size_poses();
25426 reload_fonts = false;
25427 }
25428
25429 domouse();
25430 custom_vsync();
25431 refresh(rCLEAR|rALL);
25432 }
25433 8 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c)
25434 {
25435
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
8 switch(msg)
25436 {
25437 case MSG_VSYNC:
25438 run_zq_frame();
25439 break;
25440 case MSG_GOTMOUSE:
25441 case MSG_XCHAR:
25442 ComboBrushPause=1;
25443 refresh(rMAP);
25444 ComboBrushPause=0;
25445 clear_tooltip();
25446 break;
25447 }
25448
25449 8 return GuiMenu::proc(msg,d,c);
25450 }
25451
25452 bool prv_press=false;
25453
25454 void dopreview()
25455 {
25456 refresh(rMAP);
25457
25458 while(!(gui_mouse_b()))
25459 {
25460 if(keypressed())
25461 {
25462 if(!prv_press)
25463 {
25464 prv_press=true;
25465
25466 switch(readkey()>>8)
25467 {
25468 case KEY_ESC:
25469 case KEY_ENTER:
25470 case KEY_ENTER_PAD:
25471 goto finished;
25472 break;
25473
25474 case KEY_F:
25475 Flags^=cFLAGS;
25476 refresh(rMAP);
25477 break;
25478
25479 case KEY_R:
25480 onReloadPreview();
25481 break;
25482
25483 case KEY_S:
25484 onSecretsPreview();
25485 break;
25486
25487 case KEY_C:
25488 onCopy();
25489 break;
25490
25491 case KEY_A:
25492 onAKey();
25493 break;
25494
25495 case KEY_P:
25496 onP();
25497 break;
25498
25499 case KEY_L:
25500 onShowDarkness();
25501 break;
25502
25503 case KEY_1:
25504 Map.prv_dowarp(0,0);
25505 prv_warp=0;
25506 break;
25507
25508 case KEY_2:
25509 Map.prv_dowarp(0,1);
25510 prv_warp=0;
25511 break;
25512
25513 case KEY_3:
25514 Map.prv_dowarp(0,2);
25515 prv_warp=0;
25516 break;
25517
25518 case KEY_4:
25519 Map.prv_dowarp(0,3);
25520 prv_warp=0;
25521 break;
25522
25523 case KEY_5:
25524 Map.prv_dowarp(1,0);
25525 prv_warp=0;
25526 break;
25527
25528 case KEY_6:
25529 Map.prv_dowarp(1,1);
25530 prv_warp=0;
25531 break;
25532
25533 case KEY_7:
25534 Map.prv_dowarp(1,2);
25535 prv_warp=0;
25536 break;
25537
25538 case KEY_8:
25539 Map.prv_dowarp(1,3);
25540 prv_warp=0;
25541 break;
25542
25543 case KEY_9:
25544 if(prv_twon)
25545 {
25546 prv_twon=0;
25547 Map.set_prvtime(0);
25548 prv_warp=0;
25549 }
25550 else
25551 {
25552 Map.set_prvtime(Map.get_prvscr()->timedwarptics);
25553 prv_twon=1;
25554 }
25555
25556 break;
25557
25558 case KEY_W:
25559 onShowWalkability();
25560 break;
25561
25562 case KEY_Q:
25563 onShowComboInfoCSet();
25564 break;
25565 }
25566 }
25567 else
25568 {
25569 readkey();
25570 }
25571 }
25572 else
25573 {
25574 prv_press=false;
25575 }
25576
25577 if(prv_warp)
25578 {
25579 Map.prv_dowarp(1,0);
25580 prv_warp=0;
25581 }
25582
25583 if(Map.get_prvfreeze())
25584 {
25585 if(Map.get_prvadvance())
25586 {
25587 custom_vsync();
25588 Map.set_prvadvance(0);
25589 }
25590 }
25591 else
25592 {
25593 custom_vsync();
25594 Map.set_prvadvance(0);
25595 }
25596
25597 refresh(rALL);
25598 }
25599
25600 finished:
25601 //Flags=of;
25602 reset_combo_animations();
25603 reset_combo_animations2();
25604 MouseSprite::set(ZQM_NORMAL);
25605 prv_mode=0;
25606 Map.set_prvcmb(0);
25607 Map.set_prvadvance(0);
25608 Map.set_prvfreeze(0);
25609 Map.set_prvtime(0);
25610 prv_warp=0;
25611 loadlvlpal(Map.getcolor());
25612 rebuild_trans_table();
25613 refresh(rMAP+rMENU);
25614
25615 while(gui_mouse_b())
25616 {
25617 /* do nothing */
25618 rest(1);
25619 }
25620 }
25621
25622 void call_vidmode_dlg();
25623 int32_t onZQVidMode()
25624 {
25625 call_vidmode_dlg();
25626 return D_O_K;
25627 }
25628
25629 bool screenIsScrolling()
25630 {
25631 return false;
25632 }
25633
25634 void write_includepaths()
25635 {
25636 FILE* f = fopen("includepaths.txt", "w");
25637 if(f)
25638 {
25639 fwrite(FFCore.includePathString,1,strlen(FFCore.includePathString),f);
25640 fclose(f);
25641 }
25642 }
25643
25644 11 int32_t save_config_file()
25645 {
25646
1/2
✓ Branch 0 taken 11 times.
✗ Branch 1 not taken.
11 if (!application_has_loaded) return 0;
25647
25648 char qtnametitle[20];
25649 char qtpathtitle[20];
25650 char *datapath2=(char *)malloc(2048);
25651 char *midipath2=(char *)malloc(2048);
25652 char *imagepath2=(char *)malloc(2048);
25653 char *tmusicpath2=(char *)malloc(2048);
25654 strcpy(datapath2, datapath);
25655 strcpy(midipath2, midipath);
25656 strcpy(imagepath2, imagepath);
25657 strcpy(tmusicpath2, tmusicpath);
25658 chop_path(datapath2);
25659 chop_path(midipath2);
25660 chop_path(imagepath2);
25661 chop_path(tmusicpath2);
25662 write_includepaths();
25663
25664 zc_set_config("zquest",data_path_name,datapath2);
25665 zc_set_config("zquest",midi_path_name,midipath2);
25666 zc_set_config("zquest",image_path_name,imagepath2);
25667 zc_set_config("zquest",tmusic_path_name,tmusicpath2);
25668
25669 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
25670 {
25671 window_width = al_get_display_width(all_get_display());
25672 window_height = al_get_display_height(all_get_display());
25673 zc_set_config("zquest","window_width",window_width);
25674 zc_set_config("zquest","window_height",window_height);
25675 }
25676 if (all_get_display() && !all_get_fullscreen_flag() && SaveWinPos)
25677 {
25678 int o_window_x, o_window_y;
25679 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
25680 zc_set_config("zquest", "window_x", o_window_x);
25681 zc_set_config("zquest", "window_y", o_window_y);
25682 }
25683
25684 byte b = 0;
25685 for(int32_t x=0; x<7; x++)
25686 {
25687 set_bit(&b,x,LayerMaskInt[x]);
25688 }
25689
25690 zc_set_config("zquest","layer_mask",b);
25691
25692 flush_config_file();
25693 #ifdef __EMSCRIPTEN__
25694 em_sync_fs();
25695 #endif
25696 free(datapath2);
25697 free(midipath2);
25698 free(imagepath2);
25699 free(tmusicpath2);
25700 return 0;
25701 11 }
25702
25703 int32_t d_timer_proc(int32_t msg, DIALOG *d, int32_t c)
25704 {
25705 //these are here to bypass compiler warnings about unused arguments
25706 c=c;
25707 d=d;
25708
25709 switch(msg)
25710 {
25711 case MSG_IDLE:
25712 #ifdef _WIN32
25713 if(zqUseWin32Proc != FALSE)
25714 win32data.Update(Frameskip); //experimental win32 fixes
25715
25716 #endif
25717
25718 // This has been crashing on Windows, and it saves plenty without it
25719 //check_autosave();
25720 break;
25721 }
25722
25723 return D_O_K;
25724 }
25725
25726 void check_autosave()
25727 {
25728 if (!first_save)
25729 return;
25730
25731 if(AutoSaveInterval>0)
25732 {
25733 time(&auto_save_time_current);
25734 auto_save_time_diff = difftime(auto_save_time_current,auto_save_time_start);
25735
25736 if(auto_save_time_diff>AutoSaveInterval*60)
25737 {
25738 MouseSprite::set(ZQM_NORMAL);
25739 replace_extension(last_timed_save, filepath, "qt0", 2047);
25740 set_last_timed_save(last_timed_save);
25741 go();
25742
25743 if((header.zelda_version != ZELDA_VERSION || header.build != VERSION_BUILD))
25744 {
25745 jwin_alert("Auto Save","This quest was saved in an older version of ZQuest.","If you wish to use the autosave feature, you must manually","save the files in this version first.","OK",NULL,13,27,get_zc_font(font_lfont));
25746 time(&auto_save_time_start);
25747 comeback();
25748 return;
25749 }
25750
25751 int32_t ret = save_quest(last_timed_save, true);
25752
25753 if(ret)
25754 {
25755 jwin_alert("Error","Timed save did not complete successfully.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
25756 set_last_timed_save(nullptr);
25757 }
25758
25759 save_config_file();
25760 time(&auto_save_time_start);
25761 comeback();
25762 }
25763 }
25764 }
25765
25766 void flushItemCache(bool) {}
25767 void ringcolor(bool forceDefault)
25768 {
25769 forceDefault=forceDefault;
25770 }
25771
25772 bool item_disabled(int32_t)
25773 {
25774 return false;
25775 }
25776
25777 int32_t onCmdExit()
25778 {
25779 // replaces onExit for the -large button command "Exit"
25780 close_button_quit = true;
25781 return 0;
25782 }
25783
25784 int32_t onQuickCompile()
25785 {
25786 if(do_compile_and_slots(1,false))
25787 {
25788 saved = false;
25789 InfoDialog("Quick Compile","Success!").show();
25790 }
25791 else
25792 {
25793 InfoDialog("Quick Compile","Failure!").show();
25794 }
25795 return 0;
25796 }
25797 int32_t onSmartCompile()
25798 {
25799 if(do_compile_and_slots(2,false))
25800 {
25801 saved = false;
25802 InfoDialog("Smart Compile","Success!").show();
25803 }
25804 else
25805 {
25806 InfoDialog("Smart Compile","Failure!").show();
25807 }
25808 return 0;
25809 }
25810
25811 int32_t strchrnum(char const* str, char c)
25812 {
25813 for(int32_t i=0; str[i]; ++i)
25814 {
25815 if(str[i]==c)
25816 {
25817 return i;
25818 }
25819 }
25820
25821 return -1;
25822 }
25823
25824 int32_t get_longest_line_length(FONT *f, char* str)
25825 {
25826 int32_t maxlen=0;
25827 char* tmpstr = str;
25828 char temp=0;
25829 int32_t t=0;
25830 int32_t new_t=-1;
25831 while(tmpstr[0])
25832 {
25833 t=strchrnum(tmpstr, '\n');
25834
25835 if(t==-1)
25836 {
25837 t=(int32_t)strlen(tmpstr);
25838 }
25839
25840 if((uint32_t)t!=strlen(tmpstr))
25841 {
25842 new_t=t+1;
25843 }
25844 else
25845 {
25846 new_t=-1;
25847 }
25848
25849 temp = tmpstr[t];
25850 tmpstr[t]=0;
25851 maxlen=zc_max(maxlen,text_length(f, tmpstr));
25852 tmpstr[t]=temp;
25853
25854 if(new_t!=-1)
25855 {
25856 tmpstr+=new_t;
25857 }
25858 else break;
25859 }
25860 return maxlen;
25861 }
25862
25863 int32_t count_lines(char const* str)
25864 {
25865 int32_t count=1;
25866
25867 for(word i=0; i<strlen(str); ++i)
25868 {
25869 if(str[i]=='\n')
25870 {
25871 ++count;
25872 }
25873 }
25874
25875 return count;
25876 }
25877
25878 void debug_pos(size_and_pos const& pos, int color)
25879 {
25880 if(pos.w < 1 || pos.h < 1)
25881 return;
25882 if(pos.xscale > 1 || pos.yscale > 1)
25883 {
25884 auto maxind = pos.w*pos.h;
25885 for(auto q = 0; q < maxind; ++q)
25886 {
25887 auto& sub = pos.subsquare(q);
25888 if(sub.x < 0) break;
25889 highlight_sqr(screen, color, sub, 1);
25890 }
25891 }
25892 else
25893 {
25894 if(pos.fw > -1 && pos.fh > -1)
25895 highlight_frag(screen, color, pos, 1);
25896 else highlight_sqr(screen, color, pos, 1);
25897 }
25898 }
25899
25900 void textbox_out(BITMAP* dest, FONT* font, int x, int y, int fg, int bg, char const* str, int align, size_and_pos* dims)
25901 {
25902 static size_and_pos nilsz;
25903 size_and_pos& txbox = dims ? *dims : nilsz;
25904
25905 char* kill = (char*)malloc(strlen(str)+1);
25906 char *tmpstr = kill;
25907 strcpy(tmpstr,str);
25908
25909 while(tmpstr[0] == '\n')
25910 ++tmpstr;
25911 int len = strlen(tmpstr);
25912 while(tmpstr[len-1] == '\n')
25913 tmpstr[--len] = 0;
25914
25915 txbox.x=x;
25916 txbox.y=y;
25917 int32_t lines=count_lines(tmpstr);
25918 txbox.w = 1;
25919 txbox.h = lines;
25920 txbox.xscale = get_longest_line_length(font, tmpstr);
25921 txbox.yscale = text_height(font);
25922
25923 int ax = 0; //Aligned x
25924 switch(align)
25925 {
25926 case 0: //left
25927 break;
25928 case 1: //center
25929 txbox.x -= txbox.xscale/2;
25930 ax = txbox.xscale/2;
25931 break;
25932 case 2: //right
25933 txbox.x -= txbox.xscale;
25934 ax = txbox.xscale;
25935 break;
25936 }
25937
25938 int bw = txbox.w*txbox.xscale;
25939 int bh = txbox.h*txbox.yscale;
25940 BITMAP* outbmp = create_bitmap_ex(8, bw, bh);
25941 clear_to_color(outbmp, bg);
25942
25943 char temp = 0;
25944 int32_t t=0;
25945 int32_t new_t=-1;
25946 int32_t line=0;
25947
25948 while(tmpstr[t])
25949 {
25950 t=strchrnum(tmpstr, '\n');
25951
25952 if(t==-1)
25953 t=(int32_t)strlen(tmpstr);
25954
25955 if((uint32_t)t!=strlen(tmpstr))
25956 new_t=t+1;
25957 else
25958 new_t=-1;
25959
25960 temp = tmpstr[t];
25961 tmpstr[t]=0;
25962 gui_textout_ln(outbmp, font, (ucc*)tmpstr, ax, (line*txbox.yscale), fg, -1, align);
25963 tmpstr[t]=temp;
25964 ++line;
25965
25966 if(new_t!=-1)
25967 {
25968 tmpstr+=new_t;
25969 t=0;
25970 }
25971 }
25972
25973 blit(outbmp, dest, 0, 0, txbox.x, txbox.y, bw, bh);
25974 destroy_bitmap(outbmp);
25975 free(kill);
25976 }
25977
25978 void highlight_sqr(BITMAP* dest, int color, int x, int y, int w, int h, int thick)
25979 {
25980 for(int q = 0; q < thick; ++q)
25981 {
25982 safe_rect(dest, x+q, y+q, x+w-1-q, y+h-1-q, color);
25983 }
25984 }
25985 void highlight_sqr(BITMAP* dest, int color, size_and_pos const& rec, int thick)
25986 {
25987 highlight_sqr(dest, color, rec.x, rec.y, rec.tw(), rec.th(), thick);
25988 }
25989 void highlight_frag(BITMAP* dest, int color, int x1, int y1, int w, int h, int fw, int fh, int thick)
25990 {
25991 int xc = x1+fw-1;
25992 int yc = y1+fh-1;
25993 int x2 = x1+w-1;
25994 int y2 = y1+h-1;
25995
25996 hline(dest, x1, y1, x2, color);
25997 vline(dest, x1, y1, y2, color);
25998
25999 hline(dest, x1, y2, xc, color);
26000 vline(dest, x2, y1, yc, color);
26001 hline(dest, xc, yc, x2, color);
26002 vline(dest, xc, yc, y2, color);
26003 }
26004 void highlight_frag(BITMAP* dest, int color, size_and_pos const& rec, int thick)
26005 {
26006 highlight_frag(dest, color, rec.x, rec.y, rec.tw(), rec.th(), rec.fw, rec.fh, thick);
26007 }
26008
26009 void highlight(BITMAP* dest, size_and_pos& hl)
26010 {
26011 if(hl.fw > -1 && hl.fh > -1)
26012 {
26013 highlight_frag(dest, hl.data[1], hl, hl.data[0]);
26014 }
26015 else highlight_sqr(dest, hl.data[1], hl, hl.data[0]);
26016 }
26017
26018 std::pair<int, int> get_box_text_size(char const* tipmsg, double txscale)
26019 {
26020 if(txscale < 1) txscale = 1;
26021 char* kill = (char*)malloc(strlen(tipmsg)+1);
26022 char *tmpstr = kill;
26023 strcpy(tmpstr,tipmsg);
26024
26025 while(tmpstr[0] == '\n')
26026 ++tmpstr;
26027 int len = strlen(tmpstr);
26028 while(tmpstr[len-1] == '\n')
26029 tmpstr[--len] = 0;
26030
26031 int32_t lines = count_lines(tmpstr);
26032 int txlen = get_longest_line_length(font, tmpstr);
26033 int txhei = lines*text_height(font);
26034 int tx_sclen = (txlen * txscale);
26035 int tx_schei = (txhei * txscale);
26036 int w = tx_sclen + 8 + 1;
26037 int h = tx_schei + 8 + 1;
26038 if (w > zq_screen_w)
26039 w = zq_screen_w;
26040 if (h > zq_screen_h)
26041 h = zq_screen_h;
26042 return {w, h};
26043 }
26044
26045 void draw_box(BITMAP* destbmp, size_and_pos* pos, char const* tipmsg, double txscale)
26046 {
26047 if(txscale < 1) txscale = 1;
26048 char* kill = (char*)malloc(strlen(tipmsg)+1);
26049 char *tmpstr = kill;
26050 strcpy(tmpstr,tipmsg);
26051
26052 while(tmpstr[0] == '\n')
26053 ++tmpstr;
26054 int len = strlen(tmpstr);
26055 while(tmpstr[len-1] == '\n')
26056 tmpstr[--len] = 0;
26057
26058 auto& box = *pos;
26059 clear_bitmap(destbmp);
26060
26061 int32_t lines=count_lines(tmpstr);
26062 int txlen = get_longest_line_length(font, tmpstr);
26063 int txhei = lines*text_height(font);
26064 int tx_sclen = (txlen * txscale);
26065 int tx_schei = (txhei * txscale);
26066 box.w = tx_sclen + 8 + 1;
26067 box.h = tx_schei + 8 + 1;
26068 if (box.w > zq_screen_w)
26069 box.w = zq_screen_w;
26070 if (box.h > zq_screen_h)
26071 box.h = zq_screen_h;
26072
26073 if(box.x+box.w>=zq_screen_w)
26074 {
26075 box.x=(zq_screen_w - box.w);
26076 }
26077
26078 if(box.y+box.h>=zq_screen_h)
26079 {
26080 box.y=(zq_screen_h - box.h);
26081 }
26082
26083 rectfill(destbmp, 1, 1, box.w-3, box.h-3, jwin_pal[jcTEXTBG]);
26084 rect(destbmp, 0, 0, box.w-2, box.h-2, jwin_pal[jcTEXTFG]);
26085 vline(destbmp, box.w-1, 0, box.h-1, jwin_pal[jcTEXTFG]);
26086 hline(destbmp, 1, box.h-1, box.w-2, jwin_pal[jcTEXTFG]);
26087 destbmp->line[box.h-1][0]=0;
26088 destbmp->line[0][box.w-1]=0;
26089
26090 char temp = 0;
26091 int32_t t=0;
26092 int32_t new_t=-1;
26093 int32_t line=0;
26094
26095 BITMAP* txbmp = create_bitmap_ex(8,box.w,box.h);
26096 clear_bitmap(txbmp);
26097 while(tmpstr[t])
26098 {
26099 t=strchrnum(tmpstr, '\n');
26100
26101 if(t==-1)
26102 {
26103 t=(int32_t)strlen(tmpstr);
26104 }
26105
26106 if((uint32_t)t!=strlen(tmpstr))
26107 {
26108 new_t=t+1;
26109 }
26110 else
26111 {
26112 new_t=-1;
26113 }
26114
26115 temp = tmpstr[t];
26116 tmpstr[t]=0;
26117 textprintf_ex(txbmp, font, 0, (line*text_height(font)), jwin_pal[jcTEXTFG], -1, "%s", tmpstr);
26118 tmpstr[t]=temp;
26119 ++line;
26120
26121 if(new_t!=-1)
26122 {
26123 tmpstr+=new_t;
26124 t=0;
26125 }
26126 }
26127 masked_stretch_blit(txbmp,destbmp,0,0,txlen,txhei,4,4,tx_sclen,tx_schei);
26128 destroy_bitmap(txbmp);
26129 free(kill);
26130 }
26131
26132 void update_tooltip(int32_t x, int32_t y, size_and_pos const& sqr, char const* tipmsg, double scale)
26133 {
26134 update_tooltip(x,y,sqr.x,sqr.y,sqr.w*sqr.xscale,sqr.h*sqr.yscale,tipmsg,sqr.fw,sqr.fh,scale);
26135 }
26136 void update_tooltip(int32_t x, int32_t y, int32_t tx, int32_t ty, int32_t tw, int32_t th, char const* tipmsg, int fw, int fh, double scale)
26137 {
26138 if(!EnableTooltips)
26139 {
26140 return;
26141 }
26142
26143 ttip_install(ttip_global_id, tipmsg, tx, ty, tw, th, x, y, fw, fh);
26144 }
26145
26146 void ZQ_ClearQuestPath()
26147 {
26148 zc_set_config("zquest","win_last_quest",(char const*)nullptr);
26149 strcpy(filepath,"");
26150 }
26151
26152 //FFCore
26153
26154 void FFScript::init()
26155 {
26156 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
26157 numscriptdraws = 0;
26158 max_ff_rules = qr_MAX;
26159 temp_no_stepforward = 0;
26160 nostepforward = 0;
26161
26162 coreflags = 0;
26163 skip_ending_credits = 0;
26164 music_update_cond = 0;
26165 music_update_flags = 0;
26166 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
26167
26168 //for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
26169 int32_t usr_midi_volume = usr_digi_volume = usr_sfx_volume = usr_music_volume = usr_panstyle = 0;
26170 FF_hero_action = 0;
26171 enemy_removal_point[spriteremovalY1] = -32767;
26172 enemy_removal_point[spriteremovalY2] = 32767;
26173 enemy_removal_point[spriteremovalX1] = -32767;
26174 enemy_removal_point[spriteremovalX2] = 32767;
26175 enemy_removal_point[spriteremovalZ1] = -32767;
26176 enemy_removal_point[spriteremovalZ2] = 32767;
26177
26178 for ( int32_t q = 0; q < 4; q++ )
26179 {
26180 FF_screenbounds[q] = 0;
26181 FF_screen_dimensions[q] = 0;
26182 FF_subscreen_dimensions[q] = 0;
26183 FF_eweapon_removal_bounds[q] = 0;
26184 FF_lweapon_removal_bounds[q] = 0;
26185 }
26186 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
26187 {
26188 FF_clocks[q] = 0;
26189 }
26190 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
26191 {
26192 ScriptDrawingRules[q] = 0;
26193 }
26194 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
26195 {
26196 FF_UserMidis[q] = 0;
26197 }
26198 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
26199 kb_typing_mode = false;
26200 initIncludePaths();
26201 }
26202
26203 void FFScript::updateIncludePaths()
26204 {
26205 includePaths.clear();
26206 int32_t pos = 0; int32_t pathnumber = 0;
26207 for ( int32_t q = 0; includePathString[pos]; ++q )
26208 {
26209 int32_t dest = 0;
26210 char buf[2048] = {0};
26211 while(includePathString[pos] != ';' && includePathString[pos])
26212 {
26213 buf[dest] = includePathString[pos];
26214 ++pos;
26215 ++dest;
26216 }
26217 ++pos;
26218 string str(buf);
26219 includePaths.push_back(str);
26220 }
26221 }
26222
26223 void FFScript::initIncludePaths()
26224 {
26225 memset(includePathString,0,sizeof(includePathString));
26226 FILE* f = fopen("includepaths.txt", "r");
26227 if(f)
26228 {
26229 int32_t pos = 0;
26230 int32_t c;
26231 do
26232 {
26233 c = fgetc(f);
26234 if(c!=EOF)
26235 includePathString[pos++] = c;
26236 }
26237 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
26238 if(pos<MAX_INCLUDE_PATH_CHARS)
26239 includePathString[pos] = '\0';
26240 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
26241 fclose(f);
26242 }
26243 else strcpy(includePathString, "include/;headers/;scripts/;");
26244 al_trace("Full path string is: ");
26245 safe_al_trace(includePathString);
26246 al_trace("\n");
26247 updateIncludePaths();
26248
26249 for ( size_t q = 0; q < includePaths.size(); ++q )
26250 {
26251 al_trace("Include path %zu: ",q);
26252 safe_al_trace(includePaths.at(q).c_str());
26253 al_trace("\n");
26254 }
26255 }
26256
26257 int32_t FFScript::getQRBit(int32_t rule)
26258 {
26259 return ( get_qr(rule) ? 1 : 0 );
26260 }
26261
26262 int32_t FFScript::getTime(int32_t type)
26263 {
26264 //struct tm *tm_struct = localtime(time(NULL));
26265 struct tm * tm_struct;
26266 time_t rawtime;
26267 time (&rawtime);
26268 tm_struct = localtime (&rawtime);
26269
26270 switch(type)
26271 {
26272 case curyear:
26273 {
26274 int32_t year = tm_struct->tm_year + 1900; /* year */
26275 //year format starts at 1900, so we add it to the return
26276 return year;
26277
26278 }
26279 case curmonth:
26280 {
26281 int32_t month = tm_struct->tm_mon +1; /* month */
26282 //Months start at 0, but we want 1->12
26283 return month;
26284 }
26285 case curday_month:
26286 {
26287 int32_t day_month = tm_struct->tm_mday; /* day of the month */
26288 return day_month;
26289 }
26290 case curday_week:
26291 {
26292 int32_t day_week = tm_struct->tm_wday; /* day of the week */
26293 return day_week;
26294 }
26295 case curhour:
26296 {
26297 int32_t hour = tm_struct->tm_hour; /* hours */
26298 return hour;
26299 }
26300 case curminute:
26301 {
26302 int32_t minutes = tm_struct->tm_min; /* minutes */
26303 return minutes;
26304 }
26305 case cursecond:
26306 {
26307 int32_t secs = tm_struct->tm_sec; /* seconds */
26308 return secs;
26309 }
26310 case curdayyear:
26311 {
26312 int32_t day_year = tm_struct->tm_yday; /* day in the year */
26313 return day_year;
26314 }
26315 case curDST:
26316 {
26317 int32_t isDST = tm_struct->tm_isdst; /* daylight saving time */
26318 return isDST;
26319 }
26320 default: return -1;
26321
26322 }
26323 }
26324
26325 extern const char *itemclass_help_string_defaults[itype_max];
26326
26327 /* end */
26328
26329 24576 int32_t FFScript::getQuestHeaderInfo(int32_t type)
26330 {
26331 24576 return quest_format[type];
26332 }
26333
26334 bool isSideViewGravity(int32_t t)
26335 {
26336 return (Map.CurrScr()->flags7&fSIDEVIEW) != 0;
26337 }
26338
26339
26340
26341
26342 void FFScript::ZScriptConsole(bool open)
26343 {
26344
26345
26346 #ifdef _WIN32
26347 if ( console_is_open )
26348 {
26349 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
26350 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
26351 zscript_coloured_console.gotoxy(0,0);
26352 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
26353 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
26354 }
26355 else
26356 {
26357 //close
26358 zscript_coloured_console.Close();
26359 }
26360 #endif
26361 }
26362
26363 template <typename ...Params>
26364 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
26365 {
26366 #ifdef _WIN32
26367 initConsole();
26368 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)... );
26369 #endif
26370 }
26371
26372 int32_t getpitfall(int32_t x, int32_t y){return 0;}
26373
26374 bool update_hw_pal = false;
26375 void update_hw_screen()
26376 {
26377 if (is_headless())
26378 return;
26379
26380 framecnt++;
26381
26382 zc_process_display_events();
26383 if (update_hw_pal)
26384 {
26385 zc_set_palette(RAMpal);
26386 update_hw_pal = false;
26387 }
26388
26389 render_timer_wait();
26390 render_zq();
26391 }
26392
26393 bool checkCost(int32_t ctr, int32_t amnt)
26394 {
26395 if(!game) return true;
26396 if(amnt <= 0) return true;
26397 switch (ctr)
26398 {
26399 case crMONEY: //rupees
26400 {
26401 if ( current_item_power(itype_wallet) ) return true;
26402 break;
26403 }
26404 case crMAGIC: //magic
26405 {
26406 if (get_qr(qr_ENABLEMAGIC))
26407 {
26408 return (((current_item_power(itype_magicring) > 0)
26409 ? game->get_maxmagic()
26410 : game->get_magic()+game->get_dmagic())>=amnt*game->get_magicdrainrate());
26411 }
26412 return true;
26413 }
26414 case crARROWS:
26415 {
26416 if(current_item_power(itype_quiver))
26417 return true;
26418 if(!get_qr(qr_TRUEARROWS))
26419 return checkCost(crMONEY, amnt);
26420 break;
26421 }
26422 case crBOMBS:
26423 {
26424 if(current_item_power(itype_bombbag))
26425 return true;
26426 break;
26427 }
26428 case crSBOMBS:
26429 {
26430 if(current_item_power(itype_bombbag)
26431 && itemsbuf[current_item_id(itype_bombbag)].flags & item_flag1)
26432 return true;
26433 break;
26434 }
26435 }
26436 return (game->get_counter(ctr)+game->get_dcounter(ctr)>=amnt);
26437 }
26438 bool checkmagiccost(int32_t itemid, bool checkTime)
26439 {
26440 if(itemid < 0)
26441 {
26442 return false;
26443 }
26444 itemdata const& id = itemsbuf[itemid];
26445 return checkCost(id.cost_counter[0], id.cost_amount[0])
26446 && checkCost(id.cost_counter[1], id.cost_amount[1]);
26447 }
26448
26449 void payCost(int32_t ctr, int32_t amnt, int32_t tmr, bool ignoreTimer)
26450 {
26451 return;
26452 }
26453 void paymagiccost(int32_t itemid, bool ignoreTimer, bool onlyTimer)
26454 {
26455 return;
26456 }
26457 bool is_in_scrolling_region()
26458 {
26459 return false;
26460 }
26461
26462 void enter_sys_pal(){}
26463 void exit_sys_pal(){}
26464
26465 void replay_step_comment(std::string comment) {}
26466 bool replay_is_active() {return false;}
26467 bool replay_is_replaying() {return false;}
26468 bool replay_version_check(int min, int max) {return false;}
26469 bool replay_is_debug() {return false;}
26470 int32_t item::run_script(int32_t mode){return 0;};
26471 ffcdata* slopes_getFFC(int id)
26472 {
26473 return nullptr;
26474 }
26475
26476 #ifdef __EMSCRIPTEN__
26477 extern "C" void open_test_mode()
26478 {
26479 int dmap = -1;
26480 int32_t pal = Map.getcolor();
26481 for(auto q = 0; q < MAXDMAPS; ++q)
26482 {
26483 if(DMaps[q].map == Map.getCurrMap())
26484 {
26485 if(pal == DMaps[q].color)
26486 {
26487 dmap = q;
26488 break;
26489 }
26490 if(dmap < 0)
26491 dmap = q;
26492 }
26493 }
26494 if(dmap < 0) dmap = 0;
26495
26496 em_open_test_mode(filepath, dmap, Map.getCurrScr(), -1);
26497 }
26498
26499 extern "C" void get_shareable_url()
26500 {
26501 EM_ASM({
26502 ZC.setShareableUrl({open: UTF8ToString($0), map: $1, screen: $2});
26503 }, filepath, Map.getCurrMap(), Map.getCurrScr());
26504 }
26505 #endif
26506
26507 11 void setZScriptVersion(int32_t v){}
26508